Skip to content

Conversation

@mshmoustafa
Copy link
Contributor

@mshmoustafa mshmoustafa commented Nov 21, 2025

Motivation / Description / Changes introduced

We technically say that these queries are Postgresql, but many queries weren't valid postgresql syntax so this fixes that plus fixes a couple typos and small logic simplifications.

Generally:

  • DATE_DIFF was replaced by EXTRACT/EPOCH
  • DATE_DIFF('s', start_time, end_time)::float > 0 was replaced with end_time > start_time when possible
  • some typo fixes

Links to discussion, or Linear ticket (if applicable)

Additional comments

@github-actions
Copy link

Preview this PR here: https://dev-docs.revenuecat.com/pr-1260/

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR converts SQL queries to valid PostgreSQL syntax by replacing non-standard DATE_DIFF function calls with PostgreSQL-compatible alternatives. The changes ensure these queries, which were previously incompatible with PostgreSQL despite being labeled as such, can now execute correctly.

Key changes:

  • Replaced DATE_DIFF calls with EXTRACT(EPOCH FROM ...) for timestamp calculations or simplified to direct timestamp comparisons where appropriate
  • Corrected column references from price to price_in_usd to match the actual schema
  • Replaced hardcoded dates with parameterized placeholders for better reusability

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
scheduled-data-exports_1.pgsql Removed redundant DATE_DIFF validation check
scheduled-data-exports_2.pgsql Removed redundant DATE_DIFF validation check
scheduled-data-exports_4.pgsql Removed redundant DATE_DIFF validation check
scheduled-data-exports_7.pgsql Removed redundant DATE_DIFF validation check
scheduled-data-exports_9.pgsql Removed redundant DATE_DIFF validation check
scheduled-data-exports_10.pgsql Simplified DATE_DIFF check to direct timestamp comparison
scheduled-data-exports_11.pgsql Converted DATE_DIFF to EXTRACT/EPOCH, fixed price column name, improved formatting
scheduled-data-exports_12.pgsql Converted DATE_DIFF to EXTRACT/EPOCH, fixed price column name, parameterized hardcoded dates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mshmoustafa mshmoustafa marked this pull request as ready for review November 21, 2025 21:06
@mshmoustafa mshmoustafa requested a review from a team as a code owner November 21, 2025 21:06
@mshmoustafa
Copy link
Contributor Author

@dpannasch can you double check some of the changes I made? I think I kept the logic the same, and tested them locally on real data, but just want another set of eyes on them :)

WHERE date(effective_end_time) > [targeted_date]
AND date(start_time) <= [targeted_date]
AND is_trial_period = 'false'
AND DATE_DIFF('s', start_time, end_time)::float > 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, but for the few queries where this filter is just removed, what's the line of reasoning?

Copy link
Contributor Author

@mshmoustafa mshmoustafa Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was debating this, but I was thinking that if effective_end_time > date and start_time <= date, then it's start_time <= date < effective_end_time, so end_time - start_time is always > 0 and the condition is redundant. But I know that start_time > end_time does happen, if we want to keep this condition in symbolically, I'm totally ok with that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the symbolic part I'm not concerned about at all, in fact this is one of those weird filters that I think is nonsensical to customers and is only in there because Charts does it that way. I'd maybe run a few test queries to verify that the same set of transactions that this filter excludes are also excluded when it's removed, but your logic for why it should makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants