Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for REGCLASSOID type #108

Merged
merged 6 commits into from
Aug 8, 2024
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
8 changes: 6 additions & 2 deletions src/pgduckdb_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,12 @@ ConvertPostgresToDuckColumnType(Form_pg_attribute &attribute) {
}
return duck_type;
}
default:
return duckdb::LogicalType::USER("UnsupportedPostgresType");
case REGCLASSOID:
return duckdb::LogicalTypeId::INTEGER;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works, do keep in mind that this means we lose the context of what this was on the postgres side this way.
We'd need something similar to what we do for NumericAsDouble to differentiate between an actual INT4 and a REGCLASSOID

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah definitely. I added this because it was useful for me debugging internals but agree that we're losing information here.

default: {
std::string name = "UnsupportedPostgresType (Oid=" + std::to_string(type) + ")";
return duckdb::LogicalType::USER(name);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions test/regression/expected/type_support.out
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ SELECT * FROM json_tbl;
{}
(4 rows)

-- REGCLASSOID
CREATE TABLE regclass_tbl (a REGCLASS);
INSERT INTO regclass_tbl SELECT CAST(42 as REGCLASS);
SELECT * FROM regclass_tbl;
a
----
42
(1 row)

DROP TABLE chr;
DROP TABLE small;
DROP TABLE intgr;
Expand All @@ -244,3 +253,4 @@ DROP TABLE bigint_numeric;
DROP TABLE hugeint_numeric;
DROP TABLE uuid_tbl;
DROP TABLE json_tbl;
DROP TABLE regclass_tbl;
6 changes: 6 additions & 0 deletions test/regression/sql/type_support.sql
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ INSERT INTO json_tbl SELECT CAST(a as JSON) FROM (VALUES
) t(a);
SELECT * FROM json_tbl;

-- REGCLASSOID
CREATE TABLE regclass_tbl (a REGCLASS);
INSERT INTO regclass_tbl SELECT CAST(42 as REGCLASS);
SELECT * FROM regclass_tbl;

DROP TABLE chr;
DROP TABLE small;
DROP TABLE intgr;
Expand All @@ -140,3 +145,4 @@ DROP TABLE bigint_numeric;
DROP TABLE hugeint_numeric;
DROP TABLE uuid_tbl;
DROP TABLE json_tbl;
DROP TABLE regclass_tbl;