diff --git a/crates/datafusion_ext/src/planner/mod.rs b/crates/datafusion_ext/src/planner/mod.rs index e8d67d58c..beac657db 100644 --- a/crates/datafusion_ext/src/planner/mod.rs +++ b/crates/datafusion_ext/src/planner/mod.rs @@ -269,6 +269,16 @@ impl<'a, S: AsyncContextProvider> SqlQueryPlanner<'a, S> { } SQLDataType::Bytea => Ok(DataType::Binary), SQLDataType::Interval => Ok(DataType::Interval(IntervalUnit::MonthDayNano)), + SQLDataType::Custom(obj, _) => { + let obj = obj.to_string(); + match obj.as_str() { + // PSQL uses `pg_catalog.text` for `text` type in some cases + "pg_catalog.text" => Ok(DataType::Utf8), + _ => Err(DataFusionError::NotImplemented(format!( + "Unsupported SQL type {sql_type:?}" + ))), + } + } // Explicitly list all other types so that if sqlparser // adds/changes the `SQLDataType` the compiler will tell us on upgrade // and avoid bugs like https://github.com/apache/arrow-datafusion/issues/3059 @@ -280,7 +290,6 @@ impl<'a, S: AsyncContextProvider> SqlQueryPlanner<'a, S> { | SQLDataType::Blob(_) | SQLDataType::Datetime(_) | SQLDataType::Regclass - | SQLDataType::Custom(_, _) | SQLDataType::Array(_) | SQLDataType::Enum(_) | SQLDataType::Set(_) diff --git a/testdata/sqllogictests/pg_catalog.slt b/testdata/sqllogictests/pg_catalog.slt index c0593542e..f05664cfe 100644 --- a/testdata/sqllogictests/pg_catalog.slt +++ b/testdata/sqllogictests/pg_catalog.slt @@ -83,4 +83,37 @@ pg_catalog_test pg_description statement ok -select * from pg_catalog.pg_type; \ No newline at end of file +select * from pg_catalog.pg_type; + + +# This is one of the queries postgres uses for tab completion +# see https://github.com/GlareDB/glaredb/issues/2393 +statement ok +SELECT + c.relname, + NULL::pg_catalog.text +FROM pg_catalog.pg_class c +WHERE c.relkind IN ('r', 'S', 'v', 'm', 'f', 'p') +AND (c.relname) LIKE '%' +AND pg_catalog.pg_table_is_visible(c.oid) +AND c.relnamespace <> ( SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = 'pg_catalog') UNION ALL +SELECT NULL::pg_catalog.text, n.nspname +FROM pg_catalog.pg_namespace n +WHERE n.nspname LIKE '%' +AND n.nspname NOT LIKE E'pg\\_%' +LIMIT 1000; + +# Another query postgres uses for tab completion +# see https://github.com/GlareDB/glaredb/issues/2393 +statement ok +SELECT + c.relname, + n.nspname +FROM + pg_catalog.pg_class c, + pg_catalog.pg_namespace n +WHERE c.relnamespace = n.oid +AND c.relkind IN ('r', 'S', 'v', 'm', 'f', 'p') +AND (c.relname) LIKE '%' +AND n.nspname = 'pg_catalog' +LIMIT 1000;