Skip to content

Conversation

dentiny
Copy link
Contributor

@dentiny dentiny commented Feb 26, 2025

This doesn't implement conversion for the timetz type yet, that will be done in a follow up PR.

Partially addresses #596

Copy link
Collaborator

@JelteF JelteF left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. This is a nice start. This is only implementing the DuckDB to Postgres conversion currently, but I think this should also implement the Postgres to DuckDB conversion. Then you could also add some tests to test/regression/sql/type_support.sql and test/regression/sql/array_type_support.sql.

Comment on lines 236 to 245
Datum pg_time =
DirectFunctionCall3(time_in, CStringGetDatum(value_str.c_str()), ObjectIdGetDatum(TIMEOID), Int32GetDatum(-1));
return pg_time;
}

static Datum
ConvertTimeTzDatum(const duckdb::Value &value) {
std::string value_str = value.ToString();
Datum pg_timetz = DirectFunctionCall3(timetz_in, CStringGetDatum(value_str.c_str()), ObjectIdGetDatum(TIMETZOID),
Int32GetDatum(-1));
Copy link
Collaborator

Choose a reason for hiding this comment

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

We try to avoid calling into postgres functions when we easily can. Partially to keep conversion overhead low (formatting a number as a string and then parsing it again is not free), but primarily so we can avoid crossing the C<->C++ boundary. Crossing that boundary requires a PostgresFunctionGuard for safety, except for really trivial functions like the SomeTypeGetDatum functions.

In this case it should be fairly simple to convert the internal representations directly to eachother. A Postgres time object is a TimeADT/TimeTzADT which are really (an int64, and a 2 field struct respectively). Let's contstruct that correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think your point completely makes sense! In the latest commit, I

  • Remove the code for timetz, which I will implement by EOW (mainly due to my time constraint)
  • Use the int64 for conversion and add corresponding code/test as I did for INTERVAL

@dentiny dentiny changed the title time/timetz duckdb/postgres conversion [WIP] time/timetz duckdb/postgres conversion Feb 26, 2025
@dentiny dentiny marked this pull request as draft February 26, 2025 12:42
@dentiny dentiny changed the title [WIP] time/timetz duckdb/postgres conversion TIME type duckdb/postgres conversion Feb 27, 2025
@dentiny dentiny force-pushed the hjiang/time-and-timetz branch from 38acb22 to 43b314b Compare February 27, 2025 10:09
@dentiny dentiny marked this pull request as ready for review February 27, 2025 10:46
@dentiny dentiny requested a review from JelteF February 27, 2025 10:47
@dentiny dentiny marked this pull request as draft February 27, 2025 10:53
@dentiny dentiny changed the title TIME type duckdb/postgres conversion [WIP] TIME type duckdb/postgres conversion Feb 27, 2025
@dentiny dentiny marked this pull request as ready for review February 27, 2025 11:52
@dentiny dentiny changed the title [WIP] TIME type duckdb/postgres conversion TIME type duckdb/postgres conversion Feb 27, 2025
@JelteF JelteF merged commit 66cb6e6 into duckdb:main Feb 27, 2025
5 checks passed
@dentiny
Copy link
Contributor Author

dentiny commented Feb 27, 2025

@JelteF Thank you so much for the quick review and help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants