Skip to content

feat(postgresql): Support system columns on tables #2871

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

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/endtoend/testdata/select_system/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/1745
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/select_system/pgx/go/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions internal/endtoend/testdata/select_system/pgx/go/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions internal/endtoend/testdata/select_system/pgx/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/endtoend/testdata/select_system/pgx/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- name: GetSystemColumns :one
SELECT
tableoid, xmin, cmin, xmax, cmax, ctid
FROM test;
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/select_system/pgx/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE test (
id INT
);
14 changes: 14 additions & 0 deletions internal/endtoend/testdata/select_system/pgx/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "2"
cloud:
project: "01HAQMMECEYQYKFJN8MP16QC41"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still replacing this and the database config with test context in exec.json no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, removed

sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v5"
database:
managed: true
2 changes: 1 addition & 1 deletion internal/engine/postgresql/analyzer/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (a *Analyzer) columnInfo(ctx context.Context, field pgconn.FieldDescription
if ok {
return cinfo.(*pgColumn), nil
}
rows, err := a.pool.Query(ctx, columnQuery, field.TableOID, field.TableAttributeNumber)
rows, err := a.pool.Query(ctx, columnQuery, field.TableOID, int16(field.TableAttributeNumber))
if err != nil {
return nil, err
}
Expand Down