Skip to content

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

Description

@weeco

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

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Sep 7, 2023
  2. added a commit that references this issue on Sep 8, 2023
    a6a8db1
  3. added a commit that references this issue on Sep 9, 2023
    79c58b7
  4. weeco commented on Sep 9, 2023

    @weeco
    Author

    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

  5. added a commit that references this issue on Oct 13, 2025
    47e52a7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNew issues that hasn't been reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions