Skip to content

Conversation

JelteF
Copy link
Collaborator

@JelteF JelteF commented Mar 3, 2025

In 0.3.0 we added the duckdb.unresolved_type type and implemented a bunch of operators, aggregates and functions for it. Of course the list will always be incomplete and casts to actual types might always be necessary in some cases. But for usability we should still try to implement the most commonly used functionality. So this adds a bunch of additional things that I ran into over the past weeks:

  1. The min aggregate, this was not present in 0.3.0 by accident. Probably because DuckDB has two min aggregates.
  2. Casts to time, timetz, interval and bit
  3. Support for date_trunc, length and regexp_replace
  4. Add general support for the strftime and strptime functions. This is useful even for already resolved/casted timestamp/date values because Postgres its date formatting functions like to_char are not available in DuckDB.
  5. Operators needed to implement LIKE/ILIKE/SIMILAR TO, i.e. ~, ~~, ~~*, !~, !~~, and !~~*`
  6. Add general support for the epoch/epoch_ms/epoch_us/epoch_ns functions. These are useful for lots of data processing tasks, because often timestamps are stored as a number relative to the epoch in data files/tables.

To make the string of parsing/formatting of strftime/strptime consistent this also starts syncing the PG timezone to DuckDB.

@JelteF JelteF force-pushed the missing-unresolved-type-things branch from e3a5fc7 to 9a8a8ac Compare March 3, 2025 13:46
JelteF added 2 commits March 5, 2025 16:05
In 0.3.0 we added the `duckdb.unresolved_type` type and implemented a
bunch of operators, aggregates and functions for it. Ofcourse the list
will always be incomplete and casts to actual types might always be
necessary in some cases. But for usability we should still try to
implement the most commonly used functionality. So this adds a bunch of
additional things that I ran into over the past weeks:

1. The `min` aggregate, this was not present in 0.3.0 by accident.
   Probably because duckdb has two `min` aggregates.
2. Casts to `time`, `timetz`, `interval` and `bit`
3. Support for `date_trunc`, `length` and `regexp_replace`
4. Add general support for the `strftime` and `strptime` functions. This
   is useful even for already resolved/casted `timestamp`/`date` values
   because Postgres its date formatting functions like `to_char` are not
   available in DuckDB.
@JelteF JelteF force-pushed the missing-unresolved-type-things branch from 9a8a8ac to 61bef69 Compare March 5, 2025 15:05
@JelteF JelteF requested a review from Y-- March 7, 2025 01:57
GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged) {
return PostgresFunctionGuard(::GetConfigOption, name, missing_ok, restrict_privileged);
}
} // namespace pgduckdb::pg
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a bit on the fence since they're only used in one file, but should we move the DefineCustomVariable helpers from pgduckdb.cpp here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we should make all our functions in src/pg/*.cpp files be functions that are safe to call from C++. Since DefineCustomVariable are not, and don't really make sense to be, since they are called from _PG_init, I don't think that makes sense to move them. I'd like to move all our GUC definitions to a different file in general though.

@JelteF JelteF merged commit e479749 into main Mar 7, 2025
5 checks passed
@JelteF JelteF deleted the missing-unresolved-type-things branch March 7, 2025 13:23
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