Skip to content
Merged
Changes from 1 commit
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: 20 additions & 0 deletions src/pgduckdb_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ ConvertTimeTzDatum(const duckdb::Value &value) {
return TimeTzADTPGetDatum(result);
}

inline Datum
ConvertDuckRowDatum(const duckdb::Value &value) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should really have a separate duckdb.struct type and not reuse the duckdb.row type (but you can copy and slightly modify the implementation of duckdb.row to create this new duckdb.struct type). We need this for one important reason (and possibly a few other less important ones): When duckdb.row is part of a select list, we replace it with a * before sending it to duckdb. We don't want that for this struct type. Apart from that they can basically behave the same, but we need two separate types to make the distinction between a type that is really a multiple columns under the hood (and which thus needs * expansion) versus a type that actually is a single column with a composite type in it.

Copy link
Copy Markdown
Contributor Author

@destrex271 destrex271 Mar 25, 2025

Choose a reason for hiding this comment

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

@JelteF do we also need to give the ability to create this type from postgres? like -

CREATE TABLE tester(a duckdb.struct);
INSERT INTO TABLE tester(a) VALUES('{a:12, b:12, c:Akshat}');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also correct me if I am wrong but we are handling the star exapnsion in pgduckdb_ddl::DuckdbHandleDDL, right?
As far as I understood, pgduckdb_target_list_contains_unresolved_type_or_row function helps us in this decision, right?

auto val = value.GetValue<duckdb::StructValue>();
return pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET;
}

inline Datum
ConvertTimestampDatum(const duckdb::Value &value) {
// Extract raw int64_t value of timestamp
Expand Down Expand Up @@ -875,6 +881,11 @@ ConvertDuckToPostgresValue(TupleTableSlot *slot, duckdb::Value &value, idx_t col
slot->tts_values[col] = ConvertTimestampDatum(value);
break;
}
case 17496: {
elog(LOG, "ROW TYPEE!!!!!!!!");
slot->tts_values[col] = ConvertDuckRowDatum(value);
break;
}
case TIMESTAMPTZOID: {
duckdb::timestamp_tz_t timestamp = value.GetValue<duckdb::timestamp_tz_t>();
slot->tts_values[col] = timestamp.value - pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET;
Expand Down Expand Up @@ -1220,6 +1231,10 @@ GetPostgresDuckDBType(const duckdb::LogicalType &type) {
return UUIDOID;
case duckdb::LogicalTypeId::VARINT:
return NUMERICOID;
case duckdb::LogicalTypeId::STRUCT:
elog(LOG, "hi returning the appropriate type");
return 17496;
/* return pgduckdb::DuckdbRowOid(); */
case duckdb::LogicalTypeId::LIST: {
const duckdb::LogicalType *duck_type = &type;
while (duck_type->id() == duckdb::LogicalTypeId::LIST) {
Expand Down Expand Up @@ -1519,6 +1534,11 @@ ConvertPostgresToDuckValue(Oid attr_type, Datum value, duckdb::Vector &result, i
data[offset] = duckdb::StringVector::AddStringOrBlob(result, s);
break;
}
case duckdb::LogicalTypeId::STRUCT: {
elog(LOG, "Hi in Struct type");

break;
}
case duckdb::LogicalTypeId::LIST: {
// Convert Datum to ArrayType
auto array = DatumGetArrayTypeP(value);
Expand Down
Loading