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

pg_catalog.pg_tables uses interface{} rather than string types #2714

Closed
weeco opened this issue Sep 7, 2023 · 1 comment · Fixed by #2715
Closed

pg_catalog.pg_tables uses interface{} rather than string types #2714

weeco opened this issue Sep 7, 2023 · 1 comment · Fixed by #2715
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@weeco
Copy link

weeco commented Sep 7, 2023

Version

1.21.0

What happened?

This query:

-- name: GetTables :many
SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND
    schemaname != 'information_schema';

generates the following schema:

type GetTablesRow struct {
	Schemaname  interface{}
	Tablename   interface{}
	Tableowner  interface{}
	Tablespace  interface{}
	Hasindexes  pgtype.Bool
	Hasrules    pgtype.Bool
	Hastriggers pgtype.Bool
	Rowsecurity pgtype.Bool
}

The type for Schemaname, Tablename, Tableowner should be string and for Tablespace a string pointer instead of the interface{} I believe.

Relevant log output

No response

Database schema

No response

SQL queries

-- name: GetTables :many
SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND
    schemaname != 'information_schema';

Configuration

No response

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

@weeco weeco added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 7, 2023
orisano added a commit to orisano/sqlc that referenced this issue Sep 8, 2023
@weeco
Copy link
Author

weeco commented Sep 9, 2023

I just tested this and was able to confirm that it works. New generated output is:

const getTables = `-- name: GetTables :many
SELECT schemaname, tablename, tableowner, tablespace, hasindexes, hasrules, hastriggers, rowsecurity
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND
    schemaname != 'information_schema'
`

type GetTablesRow struct {
	Schemaname  pgtype.Text
	Tablename   pgtype.Text
	Tableowner  pgtype.Text
	Tablespace  pgtype.Text
	Hasindexes  pgtype.Bool
	Hasrules    pgtype.Bool
	Hastriggers pgtype.Bool
	Rowsecurity pgtype.Bool
}

Thank you both for the super quick turnaround @andrewmbenton and @orisano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant