sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
13.54k stars 809 forks source link

Can't generate output if internal pg table is in use #3628

Open tomee03 opened 1 month ago

tomee03 commented 1 month ago

Version

1.27.0

What happened?

Hello,

I have one view with "pg_statio_all_tables" table and I can't generate code for this view. I don't know how I can continue with this view and sqlc.

Thank you

Relevant log output

# sqlc generate                                                                                                                                                                                                                                                                                                                                                         
# package db
# ../project/codelists/000010_view_columns.up.sql:1:1: relation "pg_statio_all_tables" does not exist

Database schema

CREATE VIEW "codelists"."view_columns" AS SELECT c.table_schema,
    c.table_name,
    c.column_name AS id,
    split_part(pgd.description, '@'::text, 1) AS name,
    split_part(pgd.description, '@'::text, 2)::boolean AS required,
    split_part(pgd.description, '@'::text, 3)::boolean AS hidden,
    split_part(pgd.description, '@'::text, 4)::boolean AS editable,
    split_part(pgd.description, '@'::text, 5) AS codelist
   FROM pg_statio_all_tables st
     JOIN pg_description pgd ON pgd.objoid = st.relid
     RIGHT JOIN information_schema.columns c ON pgd.objsubid = c.ordinal_position::integer AND c.table_schema::name = st.schemaname AND c.table_name::name = st.relname
  WHERE c.table_schema::name = 'codelists'::name;

SQL queries

-- name: GetColumns :many
SELECT id, name, required, hidden, editable, codelist FROM codelists.view_columns WHERE table_name = @table_name AND table_schema = @table_schema;

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "db/queries"
    schema: ["../project/codelists", "../project/stock", "../project/iam", "../project/clients", "../project/contracts"]
    gen:
      go:
        package: "db"
        sql_package: "pgx/v5"
        out: "db"
        emit_json_tags: true
        overrides:
          - go_type:
              import: "github.com/rs/xid"
              type:  "ID"
              package: "xid"
            db_type: "public.xid"

Playground URL

No response

What operating system are you using?

Linux, macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

lenuse commented 5 days ago

I also encountered the same problem. The table creation sql and view creation sql files are not in the same sql file. This error message will appear. How to deal with it?