pg_duckdb icon indicating copy to clipboard operation
pg_duckdb copied to clipboard

Enum type support

Open Tishj opened this issue 1 year ago • 2 comments

This PR adds support for Postgres's ENUM types.

In Postgres ENUM types can not be ephemeral (exist only for the duration of a query), they have to be registered, and thus we can't just recreate the ENUM type when converting back from DuckDB -> Postgres at the end of execution.

This detail caused the biggest development overhead, we need to vendor and inherit from a templated derived class that contains the guts of the DuckDB ENUM type so we can add Postgres's ENUM member oids to it.

template <class T>
class PGDuckDBEnumTypeInfo : public EnumTypeInfoTemplated<T> {
public:
	PGDuckDBEnumTypeInfo(Vector &values_insert_order_p, idx_t dict_size_p, Vector &oid_vec)
	    : EnumTypeInfoTemplated<T>(values_insert_order_p, dict_size_p), oid_vec(oid_vec) {
	}

public:
	const Vector &
	GetMemberOids() const {
		return oid_vec;
	}

private:
	Vector oid_vec;
};

We save the ENUM member oids into this, as this is what has to be returned in the query result.

Tishj avatar Sep 19 '24 08:09 Tishj

I'm waiting on https://github.com/duckdb/pg_duckdb/pull/97 so I can add the tests with a > 'sad' etc, that will involve adding support for looking up type catalog entries, which is probably a nice bonus (but might be better as a separate PR)

Tishj avatar Sep 24 '24 07:09 Tishj

Regarding the 0.2.0 milestone: while it's not a blocker for 0.1.0 but it would be great for this to land, especially considering it's basically done. Use of ENUMs is certainly not uncommon in Postgres.

wuputah avatar Oct 01 '24 15:10 wuputah