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

Support TIMESTAMP_NS, TIMESTAMP_MS & TIMESTAMP_S #534

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

destrex271
Copy link

@destrex271 destrex271 commented Jan 15, 2025

Draft PR to support TIMESTAMP_NS, TIMESTAMP_MS & TIMESTAMP_S types available in duckdb in postgres.

Fixes #283

@destrex271
Copy link
Author

destrex271 commented Jan 15, 2025

Insert statements executed from postgres on tables in motherduck are working as expected for TIMESTAMP_MS & TIMESTAMP_S.

-- Tables created in Motherduck
CREATE TABLE timestamps_ms_tbl(a timestamp_ms);
CREATE TABLE timestamps_s_tbl(a timestamp_s);
-- ------------------------------------------------------------------------

-- Insert statements executed from postgres
INSERT INTO timestamps_ms_tbl VALUES('1992-12-12 12:12:12.1989898'::TIMESTAMP);
INSERT INTO timestamps_s_tbl VALUES('1992-12-12 12:12:12.1989898'::TIMESTAMP);

-- Selecting Data from mother duck via postgres
-- -------------------------------------------------------------------
SELECT * FROM timestamps_ms_tbl; 
-- Output:
-- 1992-12-12 12:12:12.198

SELECT * FROM timestamps_s_tbl;
-- Output
-- 1992-12-12 12:12:12

Currently working on converting TIMESTAMP_MS selected from duckdb into Postgres TIMESTAMP type

@destrex271 destrex271 marked this pull request as ready for review January 16, 2025 17:18
@destrex271
Copy link
Author

@JelteF, I tested this against some tables in Motherduck, but I’m not sure how to go about writing regression tests for this. From what I understand, the type_support tests are queries run from within PostgreSQL. Since this PR doesn’t add any new types to Postgres, I’m a bit confused about the best way to proceed.

@destrex271
Copy link
Author

Also unrelated to this issue, I noticed another problem while working on this:

image

As you can see, for some reason on motherduck timestamp_ns is being compressed to timestamp with micro second precision only.

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.

I tested this out manually using MotherDuck, and it works well. Code also looks good, but I left a few small comments on how to fix CI.

Regarding how to add similar automated tests. I don't think that's possible indeed. But one thing we can do is at least test the conversion from DuckDB to Postgres by using the duckdb.query function that was introduced in #531 (which I merged half an hour ago):

SELECT * FROM duckdb.query($$ SELECT '1992-12-12 12:12:12.123456789'::TIMESTAMP_NS as ts $$);

That query works on this branch, but not on main. If you can add similar queries for all the newly supported types then I think we can merge this.

int64_t rawValue = value.GetValue<int64_t>();

// Handle specific Timestamp unit(sec, ms, ns) types
switch(value.type().id()){
Copy link
Collaborator

Choose a reason for hiding this comment

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

needs a default case to silence the compiler warning

// 1 ms = 10^3 micro-sec
rawValue *= 1000;
break;
case duckdb::LogicalType::TIMESTAMP_NS:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to run make format to solve the formatting warning.

@destrex271
Copy link
Author

I tested this out manually using MotherDuck, and it works well. Code also looks good, but I left a few small comments on how to fix CI.

Regarding how to add similar automated tests. I don't think that's possible indeed. But one thing we can do is at least test the conversion from DuckDB to Postgres by using the duckdb.query function that was introduced in #531 (which I merged half an hour ago):

SELECT * FROM duckdb.query($$ SELECT '1992-12-12 12:12:12.123456789'::TIMESTAMP_NS as ts $$);

That query works on this branch, but not on main. If you can add similar queries for all the newly supported types then I think we can merge this.

Cool I'll update this accordingly.

@destrex271 destrex271 requested a review from JelteF January 24, 2025 18:02
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.

Support TIMESTAMP_NS, TIMESTAMP_MS & TIMESTAMP_S types
2 participants