-
Couldn't load subscription status.
- Fork 331
Description
I'm trying to run xo schema against a non-default schema in a postgresql database.
Command:
./build/darwin/amd64/0.0.0-dev/xo schema -d templates/go -o database/models/sample -g "json:\"{{ .SQLName }}\" db:\"{{ .SQLName }}\"" --schema=sample 'postgres://****:****@localhost:5432/uos?sslmode=disable' --verbose
Output:
SQL: SELECT (CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' END), c.relname, false, CASE c.relkind WHEN 'r' THEN COALESCE(obj_description(c.relname::regclass), '') WHEN 'v' THEN v.definition END AS view_def FROM pg_class c JOIN ONLY pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_views v ON n.nspname = v.schemaname AND v.viewname = c.relname WHERE n.nspname = $1 AND (CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' END) = LOWER($2)
PARAMS: [sample table]
error: pq: relation "hello" does not exist
After some investigation, this error may be caused by this schema is not the default schema of this database, and obj_description(c.relname::regclass) throws the "relation does not exist" error. The last query should only work for the tables in the default schema. Maybe the query should change to:
obj_description((n.nspname || '.' || c.relname)::regclass) to include the schema name in the parameter of obj_description function.