Skip to content

Conversation

@Scorg
Copy link

@Scorg Scorg commented Sep 16, 2025

This PR allows to avoid data loss in conversions between DATE and timestamp[tz]. It adds several options to set a fixed timezone of the Oracle server to preserve the implicit (server) timezone of DATE and TIMESTAMP Oracle types when converting them to timestamptz Postgres type and back.

Currently DATEs and TIMESTAMPs are presented as timestamp (local to any timezone) in Postgres, which assumes session's timezone. And even if foreign table's column type is set to timestamptz, the timezone is still assumed to be that of the session. To preserve a fixed/constant timezone a user is required to do explicit conversions from timestamp to timestamptz (and reversed) when working with DATE/TIEMSTAMP columns of foreign tables. This is error prone and unnecessary.

The ugly part right now is the pushdown of predicates. The conversions require analyzing multiple nodes/levels of predicate's expression, but the query is being generated in single step. It would be better to have an intermediate tree representation before stamping out the query for Oracle, where it would be possible to do complex analysis and transformations. The expression tree given by Postgres looks unfitting for this purpose.

@laurenz
Copy link
Owner

laurenz commented Sep 16, 2025

I am having trouble with this pull request.

  • It is not based on git HEAD, which would require me to merge and resolve conflicts. Please base any patches on git HEAD.

  • The patch is big, and it seems to involve things that are not part of the modified functionality (there is a commit titled "add Instant Client paths", which seems unrelated). Please avoid unrelated code churn, it makes review harder.

My biggest problem is that I don't agree with the idea — or perhaps I simply misunderstand your description:

  • When Oracle TIMESTAMP is converted to PostgreSQL timestamp without time zone, no time zone conversion takes place. There is nothing to improve here.

  • When Oracle TIMESTAMP WITH TIME ZONE is converted to PostgreSQL timestamp with time zone, there is also no time zone conversion. The (unambiguous) absolute timestamp is preserved. You lose the time zone that is part of Oracle's TIMESTAMP WITH TIME ZONE, but that is in the nature of things and cannot be avoided. There is nothing to improve here either.

The only case where the timezone parameter of the PostgreSQL session matters is when you convert between timestamps with time zone and timestamps without time zone. This is the case your pull request addresses, correct?
I tried to read the documentation patch, but I could not quite understand it, which is not great: I may not be the smartest person around, but if I don't get it, I guess a lot of users won't understand either.

Do I get it right that you are proposing a server option that governs that conversion, rather than using PostgreSQL's timezone? Why is that better?

It also seems like there are options for IMPORT FOREIGN SERVER to automatically map timestamps to the wrong PostgreSQL data type. I don't like that at all. While oracle_fdw supports converting between timestamp with time zone and timestamp without time zone, that is not something that I particularly want to encourage.

Please help me understand what you want to change and why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants