Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSql temporal types to SqlBinaryExpr #4657

Merged
merged 3 commits into from
Nov 16, 2023

Conversation

griffio
Copy link
Contributor

@griffio griffio commented Sep 23, 2023

Add some missing support for binary expressions with temporal types:

TIMESTAMP is added last to the type-order as it needs to be the result of a binary expression containing a TIMESTAMP and INTERVAL

Examples

SELECT NOW() + INTERVAL '1 day'; // DateTime 

SELECT 31 * INTERVAL '1 day'; // PGInterval

SELECT INTERVAL '1 day' + INTERVAL '3 hour'; // PGInterval

@griffio griffio changed the title Add PostgreSql temporal types Add PostgreSql temporal types to SqlBinaryExpr Sep 23, 2023
@griffio griffio marked this pull request as ready for review September 23, 2023 17:40
@griffio griffio force-pushed the add-postgresql-temporal-types branch from f79f1b6 to 6b77da1 Compare September 26, 2023 07:07
@griffio griffio force-pushed the add-postgresql-temporal-types branch from 0736643 to ba80c52 Compare October 8, 2023 16:14
@griffio griffio force-pushed the add-postgresql-temporal-types branch from ba80c52 to 71dff65 Compare October 26, 2023 15:40
@griffio griffio force-pushed the add-postgresql-temporal-types branch from 71dff65 to 150e143 Compare November 4, 2023 09:17
For encapsulatingType allow expressions to return temporal types
    PostgreSqlType.INTERVAL,
    PostgreSqlType.TIMESTAMP_TIMEZONE
    PostgreSqlType.TIMESTAMP

e.g 31 * INTERVAL '1 minute' + INTERVAL '2 days'

Timestamp should be ordered last

When binary expression contains TIMESTAMP and INTERVAL, TIMESTAMP must be selected
Extend the existing tests with binary expressions
@@ -252,12 +252,31 @@ class PostgreSqlTest {
assertThat(now).isGreaterThan(OffsetDateTime.MIN)
}

@Test fun nowPlusInterval() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor, you could also use SELECT NOW(), NOW() + INTERVAL '1 day' and compare the two values in Java/Kotlin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok - have compared now plus 1 > now

@Test fun interval() {
val interval = database.datesQueries.selectInterval().executeAsOne()
assertThat(interval).isNotNull()
assertThat(interval.getDays()).isEqualTo(1)
}

@Test fun intervalBinaryMultiplyExpression() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

Check that now + 1 is greater than now
@hfhbd hfhbd merged commit c23621c into cashapp:master Nov 16, 2023
7 checks passed
@griffio griffio deleted the add-postgresql-temporal-types branch November 17, 2023 07:28
hfhbd pushed a commit that referenced this pull request Apr 2, 2024
* Update PostgreSqlTypeResolver temporal type

For encapsulatingType allow expressions to return temporal types
    PostgreSqlType.INTERVAL,
    PostgreSqlType.TIMESTAMP_TIMEZONE
    PostgreSqlType.TIMESTAMP

e.g 31 * INTERVAL '1 minute' + INTERVAL '2 days'

Timestamp should be ordered last

When binary expression contains TIMESTAMP and INTERVAL, TIMESTAMP must be selected

* Add PostgreSql integration tests

Extend the existing tests with binary expressions

* Change test to compare two intervals

Check that now + 1 is greater than now
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.

None yet

2 participants