Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ibis/backends/postgres/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@
a = ColGen(table="a")
c = ColGen(table="c")
n = ColGen(table="n")
t = ColGen(table="t")
e = ColGen(table="e")

Check warning on line 510 in ibis/backends/postgres/__init__.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/postgres/__init__.py#L509-L510

Added lines #L509 - L510 were not covered by tests

format_type = self.compiler.f["pg_catalog.format_type"]

Expand All @@ -522,7 +524,23 @@
type_info = (
sg.select(
a.attname.as_("column_name"),
format_type(a.atttypid, a.atttypmod).as_("data_type"),
sg.case()
.when(
sge.Exists(
this=sg.select(1)
.from_(sg.table("pg_type", db="pg_catalog").as_("t"))
.join(
sg.table("pg_enum", db="pg_catalog").as_("e"),
on=sg.and_(
e.enumtypid.eq(t.oid),
t.typname.eq(format_type(a.atttypid, a.atttypmod)),
),
)
),
sge.convert("enum"),
)
.else_(format_type(a.atttypid, a.atttypmod))
.as_("data_type"),
sg.not_(a.attnotnull).as_("nullable"),
)
.from_(sg.table("pg_attribute", db="pg_catalog").as_("a"))
Expand Down
6 changes: 5 additions & 1 deletion ibis/backends/postgres/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,18 @@
name = gen_name("enum_table")
with con._safe_raw_sql("CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')") as cur:
cur.execute(f"CREATE TEMP TABLE {name} (mood mood)")
cur.execute(f"INSERT INTO {name} (mood) VALUES ('happy'), ('ok')")

Check warning on line 432 in ibis/backends/postgres/tests/test_client.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/postgres/tests/test_client.py#L432

Added line #L432 was not covered by tests
yield name
cur.execute(f"DROP TABLE {name}")
cur.execute("DROP TYPE mood")


def test_enum_table(con, enum_table):
t = con.table(enum_table)
assert t.mood.type() == dt.unknown
assert t.mood.type().is_string()
e = t.filter(t.mood == "ok")
result = e.execute()
assert len(result) == 1

Check warning on line 443 in ibis/backends/postgres/tests/test_client.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/postgres/tests/test_client.py#L440-L443

Added lines #L440 - L443 were not covered by tests


def test_parsing_oid_dtype(con):
Expand Down