-
Notifications
You must be signed in to change notification settings - Fork 540
Add postgreSql interval column result #4152
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 interval column result #4152
Conversation
...postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/PostgreSqlTypeResolver.kt
Outdated
Show resolved
Hide resolved
.../src/main/kotlin/app/cash/sqldelight/dialects/postgresql/grammar/mixins/LiteralValueMixin.kt
Outdated
Show resolved
Hide resolved
sqldelight-compiler/src/test/kotlin/app/cash/sqldelight/core/BindArgsTest.kt
Outdated
Show resolved
Hide resolved
...ts/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/grammar/PostgreSql.bnf
Show resolved
Hide resolved
...tion-postgresql/src/test/kotlin/app/cash/sqldelight/postgresql/integration/PostgreSqlTest.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice
...ts/postgresql/src/main/kotlin/app/cash/sqldelight/dialects/postgresql/grammar/PostgreSql.bnf
Outdated
Show resolved
Hide resolved
if (PsiTreeUtil.getParentOfType(this, SqlSetterExpression::class.java) != null) return | ||
if (PsiTreeUtil.getParentOfType(this, SqlCreateTableStmt::class.java) != null) return | ||
|
||
annotationHolder.createErrorAnnotation(this, "Cannot use time literal in expression") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test case for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do error tests in the fixtures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean specifically on this error annotation. They're super easy to set up a test for, it's like this where a test fixture has a comment specifically for a reported error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - specifically I was interested in the inherited LiteralValueMixin that has the restriction "Cannot use time literal in expression"
?
As both PostgreSql + ansiFixtures are run by the tests - I can't override it in the PostgreSql dialect to support the syntax
updatedAt > CURRENT_TIMESTAMP - INTERVAL '30' days
- The timestamp-literal will always run and currently fails if I override the restriction in LiteralValueMixin.
I looked at the Fixture setup and I don't think it will override the ansi
test cases even if I redeclare the test fixture timestamp-literals
in postgreSql
fixtures.
Hopefully - that makes sense and is for another PR once I understand it :)
Bind arg test is easiest to debug Add Integration test for PGInterval type
Override literal_value to support interval_expression “INTERVAL ‘1 day” is the literal expression that will be used by the TypeResolver This creates a new PostgresLiteralValue that inherits the base LiteralValueMixin LiteralValueMixin may have to be customised to support returning CURRENT_DATE_TIME etc. The base behaviour only allows assignments of timestamps.
The SqlLiteralExpr will be “INTERVAL ‘1 day’” Add CURRENT_ types to return actual types -ansi inherited was TEXT Calls the inherited “ansi” behaviour for NULL etc There is probably a better way to achieve this in future PRs as there is more to do
0a6ba07
to
a855d64
Compare
Used for debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, sorry for the missing answer in the issue, but this is exactly what I mean.
closes #4144 Look into approach for supporting INTERVAL literal column results
SELECT INTERVAL '1 day';
Override Literals, test returns
PGInterval
type.TODOs
Literals for CURRENT_DATE, CURRENT_TIME, CURRENT_DATE_TIME should also be considered.
Support
SELECT NOW() + INTERVAL '1 day';