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

Functions cannot be referenced without parenthesis #3636

Closed
JakeWharton opened this issue Nov 5, 2022 · 4 comments · Fixed by #5226
Closed

Functions cannot be referenced without parenthesis #3636

JakeWharton opened this issue Nov 5, 2022 · 4 comments · Fixed by #5226

Comments

@JakeWharton
Copy link
Member

SQLDelight Version

2.0.0-alpha04

SQLDelight Dialect

postgresql

Describe the Bug

This query fails:

create:
INSERT INTO conversations(created_at, updated_at)
VALUES (LOCALTIMESTAMP, LOCALTIMESTAMP)
RETURNING id
;

This one succeeds:

create:
INSERT INTO conversations(created_at, updated_at)
VALUES (LOCALTIMESTAMP(), LOCALTIMESTAMP())
RETURNING id
;

Can we make the former work? Or at least have an error message saying it has to be executed as a function.

Note, there are a bunch of these: https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-CURRENT

Stacktrace

/Volumes/dev/JakeWharton/thing/src/main/sqldelight/com/jakewharton/thing/db/conversations.sq: (10, 8): No column found with name LOCALTIMESTAMP
09    INSERT INTO conversations(created_at, updated_at)
10    VALUES (LOCALTIMESTAMP, LOCALTIMESTAMP)
              ^^^^^^^^^^^^^^
11    RETURNING id

/Volumes/dev/JakeWharton/thing/src/main/sqldelight/com/jakewharton/thing/db/conversations.sq: (10, 24): No column found with name LOCALTIMESTAMP
09    INSERT INTO conversations(created_at, updated_at)
10    VALUES (LOCALTIMESTAMP, LOCALTIMESTAMP)
                              ^^^^^^^^^^^^^^
11    RETURNING id
@hfhbd
Copy link
Collaborator

hfhbd commented Nov 5, 2022

Recognizing them without the parentheses only works with custom tokens. The same for the better error message, we need to "know" if you want to refer to a column or to the function. LOCALTIMESTAMP is a keyword and we should add these keywords too.

CREATE TABLE foo(id INT);

SELECT LOCALTIMESTAMP, id FROM foo;

IntelliJ also warns you:
Bildschirm­foto 2022-11-05 um 14 01 51

BTW DB2 is even worse, eg: SELECT CURRENT DATE; :)

@JakeWharton
Copy link
Member Author

I lied, LOCALTIMESTAMP() does not actually work in the DB, it merely satisfies SQLDelight (incorrectly).

@hfhbd
Copy link
Collaborator

hfhbd commented Dec 28, 2022

Yeah, because SQLDelight thinks, this is a function but does not know if this function actually exists. We should still add LOCALTIMESTAMP too.

@drewd
Copy link
Contributor

drewd commented May 3, 2024

Note, I only added the current date/time functions in the section you guys mentioned. There are actually a ton of these: https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-TABLE. More than I think is worth it at the moment.

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

Successfully merging a pull request may close this issue.

3 participants