Skip to content

Commit 3f01075

Browse files
authored
fix(postgres): handle enums by delegating to the parent class (#9769)
Handle postgres enum types as unknown. Closes #9295.
1 parent 175e362 commit 3f01075

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

ibis/backends/postgres/tests/test_client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def test_infoschema_dtypes(con):
384384

385385

386386
def test_password_with_bracket():
387-
password = f"{IBIS_POSTGRES_PASS}["
387+
password = f"{IBIS_POSTGRES_PASS}[]"
388388
quoted_pass = quote_plus(password)
389389
url = f"postgres://{IBIS_POSTGRES_USER}:{quoted_pass}@{IBIS_POSTGRES_HOST}:{IBIS_POSTGRES_PORT}/{POSTGRES_TEST_DB}"
390390
with pytest.raises(
@@ -417,3 +417,18 @@ def test_create_geospatial_table_with_srid(con):
417417
for column, dtype in zip(column_names, column_types)
418418
}
419419
)
420+
421+
422+
@pytest.fixture(scope="module")
423+
def enum_table(con):
424+
name = gen_name("enum_table")
425+
con.raw_sql("CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')")
426+
con.raw_sql(f"CREATE TEMP TABLE {name} (mood mood)")
427+
yield name
428+
con.raw_sql(f"DROP TABLE {name}")
429+
con.raw_sql("DROP TYPE mood")
430+
431+
432+
def test_enum_table(con, enum_table):
433+
t = con.table(enum_table)
434+
assert t.mood.type() == dt.unknown

ibis/backends/sql/datatypes.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,11 @@ def from_string(cls, text: str, nullable: bool | None = None) -> dt.DataType:
193193

194194
try:
195195
sgtype = sg.parse_one(text, into=sge.DataType, read=cls.dialect)
196-
return cls.to_ibis(sgtype, nullable=nullable)
197196
except sg.errors.ParseError:
198197
# If sqlglot can't parse the type fall back to `dt.unknown`
199-
pass
200-
201-
return dt.unknown
198+
return dt.unknown
199+
else:
200+
return cls.to_ibis(sgtype, nullable=nullable)
202201

203202
@classmethod
204203
def to_string(cls, dtype: dt.DataType) -> str:
@@ -468,11 +467,8 @@ def _from_ibis_Map(cls, dtype: dt.Map) -> sge.DataType:
468467
def from_string(cls, text: str, nullable: bool | None = None) -> dt.DataType:
469468
if text.lower().startswith("vector"):
470469
text = "vector"
471-
if dtype := cls.unknown_type_strings.get(text.lower()):
472-
return dtype
473470

474-
sgtype = sg.parse_one(text, into=sge.DataType, read=cls.dialect)
475-
return cls.to_ibis(sgtype, nullable=nullable)
471+
return super().from_string(text, nullable=nullable)
476472

477473

478474
class RisingWaveType(PostgresType):

0 commit comments

Comments
 (0)