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

Handle PostgreSQL system columns #1745

Closed
ndrpnt opened this issue Jul 14, 2022 · 3 comments · Fixed by #2871
Closed

Handle PostgreSQL system columns #1745

ndrpnt opened this issue Jul 14, 2022 · 3 comments · Fixed by #2871

Comments

@ndrpnt
Copy link

ndrpnt commented Jul 14, 2022

Version

1.14.0

What happened?

sqlc currently errors out with column "…" does not exist when referencing a PostgreSQL system column (tableoid, xmin, cmin, xmax, cmax or ctid) in an SQL query.

Example db-fiddle

Not sure if this should be a bug report or a feature request.

Relevant log output

column "ctid" does not exist

Database schema

CREATE TABLE test (
  id INT
);

SQL queries

SELECT ctid FROM test;

Configuration

version: 2
sql:
- schema: sql/schema.sql
  queries: sql/queries.sql
  engine: postgresql
  gen:
    go:
      out: internal/sql

Playground URL

https://play.sqlc.dev/p/0a3172295b4a8b1a7dd1f78f56a864425724d1d5118c73a45f2fd313733c6910

What operating system are you using?

No response

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@ndrpnt ndrpnt added bug Something isn't working triage New issues that hasn't been reviewed labels Jul 14, 2022
@kyleconroy kyleconroy removed the triage New issues that hasn't been reviewed label Aug 28, 2022
andrewmbenton added a commit that referenced this issue Oct 16, 2023
kyleconroy added a commit that referenced this issue Oct 18, 2023
* test: Add a test case for #1745

* feat(postgresql): Support system columns

* Remove stdlib

* Update sqlc.yaml

* Add exec.json

---------

Co-authored-by: Andrew Benton <andrew@sqlc.dev>
@kyleconroy
Copy link
Collaborator

v1.23.0 is out now, which includes this fix

@smonv
Copy link

smonv commented Jun 7, 2024

@kyleconroy I tried this feature with 1.25 but still got column does not exist error.

https://play.sqlc.dev/p/8761c174f69f3c2e47a581c049c662eb60cf481160c46b491a5ed80b2f3dd043

@swallowstalker
Copy link
Contributor

after spending some time looking into the problem, I tested it using sql.database.managed set to true, and it's working. turns out that the pg config Analyzer is doing the job of getting pg system columns, and with default config of sql.database.managed set to false, then the pg config Analyzer is not initialized since there is no db to look for system columns. the solution (maybe) is to set list of hardcoded system columns if pg config Analyzer is not set, what do you think?

related docs

example config file

version: "2"
servers:
  - engine: postgresql
    uri: "postgres://user:pass@localhost:5432/dbname?sslmode=disable"
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "querytest"
        out: "go"
        sql_package: "pgx/v5"
    database:
      managed: true

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.

4 participants