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

Postgres system columns not working #3742

Open
werjo-gridfuse opened this issue Dec 12, 2024 · 1 comment
Open

Postgres system columns not working #3742

werjo-gridfuse opened this issue Dec 12, 2024 · 1 comment
Labels
📚 postgresql bug Something isn't working

Comments

@werjo-gridfuse
Copy link

Version

1.27.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.

There was already a pull request that should fix this. And there are tests to make sure this is working. See here 1745

In this thread, there was a comment, that its not working with 1.25. Sadly its also not working with 1.27. And if you change the version to 1.23 in the playground, its also not working.

Relevant log output

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

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

SELECT xmin, cmin, xmax, cmax, ctid FROM authors;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

https://play.sqlc.dev/p/db9040344439ff1fcf601ba3e93486fca3e1b2c0644fb46e4563bbf81c675116

What operating system are you using?

No response

What database engines are you using?

No response

What type of code are you generating?

No response

@werjo-gridfuse werjo-gridfuse added the bug Something isn't working label Dec 12, 2024
@swallowstalker
Copy link
Contributor

swallowstalker commented Dec 23, 2024

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
Labels
📚 postgresql bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants