Skip to content

Commit 20237d5

Browse files
committed
fix: postgres columns
1 parent e1bc3c6 commit 20237d5

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

sqlmesh/core/engine_adapter/base_postgres.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ def _columns_query(self, table: exp.Table) -> exp.Select:
3333
"pg_catalog.format_type(atttypid, atttypmod) AS data_type",
3434
)
3535
.from_("pg_catalog.pg_attribute")
36-
.join("pg_catalog.pg_class", on="oid = attrelid")
37-
.join("pg_catalog.pg_namespace", on="oid = relnamespace")
36+
.join("pg_catalog.pg_class", on="pg_class.oid = attrelid")
37+
.join("pg_catalog.pg_namespace", on="pg_namespace.oid = relnamespace")
3838
.where(
3939
exp.and_(
4040
"attnum > 0",
4141
"NOT attisdropped",
42-
exp.column("nspname").eq(table.alias_or_name),
42+
exp.column("relname").eq(table.alias_or_name),
4343
)
4444
)
4545
)
4646
if table.args.get("db"):
47-
sql = sql.where(exp.column("relname").eq(table.args["db"].name))
47+
sql = sql.where(exp.column("nspname").eq(table.args["db"].name))
4848
return sql
4949

5050
def columns(

tests/core/engine_adapter/test_base_postgres.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def test_columns(make_mocked_engine_adapter: t.Callable):
1919
'SELECT "attname" AS "column_name", '
2020
'"pg_catalog".FORMAT_TYPE("atttypid", "atttypmod") AS "data_type" '
2121
'FROM "pg_catalog"."pg_attribute" '
22-
'JOIN "pg_catalog"."pg_class" ON "oid" = "attrelid" '
23-
'JOIN "pg_catalog"."pg_namespace" ON "oid" = "relnamespace" '
24-
"""WHERE ("attnum" > 0 AND NOT "attisdropped" AND "nspname" = 'table') AND "relname" = 'db'"""
22+
'JOIN "pg_catalog"."pg_class" ON "pg_class"."oid" = "attrelid" '
23+
'JOIN "pg_catalog"."pg_namespace" ON "pg_namespace"."oid" = "relnamespace" '
24+
"""WHERE ("attnum" > 0 AND NOT "attisdropped" AND "relname" = 'table') AND "nspname" = 'db'"""
2525
)
2626
assert resp == {"col": exp.DataType.build("INT")}
2727

0 commit comments

Comments
 (0)