Skip to content

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

@andrewmbenton

Description

@andrewmbenton

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions