Skip to content

Generated code is incorrect for SQL "value" functions in FROM clauses #2451

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

Closed
andrewmbenton opened this issue Jul 13, 2023 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@andrewmbenton
Copy link
Collaborator

Version

Other

What happened?

From working on #2449 I discovered that sqlc doesn't handle some valid queries with function calls like current_date in FROM clauses correctly. I have only tried this with postgresql, but a similar issue may be present for other engines.

For the query SELECT * FROM current_date; sqlc generates a function returning a struct with no fields, which is of course not the desired result.

For the query SELECT date FROM current_date AS date; (which is perfectly valid) sqlc just prints an error:

query.sql:2:8: column "date" does not exist

Here's psql output for that query:

postgres=# SELECT date FROM current_date AS date;
    date    
------------
 2023-07-13
(1 row)

Relevant log output

No response

Database schema

No response

SQL queries

SELECT * FROM current_date;

SELECT date FROM current_date AS date;

Configuration

No response

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@andrewmbenton andrewmbenton added bug Something isn't working triage New issues that hasn't been reviewed labels Jul 13, 2023
@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Oct 2, 2023
@kyleconroy
Copy link
Collaborator

While it's not completely the same, I believe that solving #1322 will also fix this issue.

Duplicate of #1322

@kyleconroy kyleconroy closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants