[ 
https://issues.apache.org/jira/browse/CALCITE-6045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17774265#comment-17774265
 ] 

Julian Hyde commented on CALCITE-6045:
--------------------------------------

This all sounds right. I have been feeling guilty for several years that 
{{CURRENT_TIMESTAMP}} returns a {{TIMESTAMP}} rather than the {{TIMESTAMP WITH 
TIME ZONE}} as required by the SQL standard.

We should fix it, but it will be a breaking change. Also, do you think the 
{{TIMESTAMP WITH TIME ZONE}} data type is in good enough shape to support it?

Note that there is also {{LOCAL_TIMESTAMP}}, which I believe is of type 
{{TIMESTAMP}} and is in the session time zone. I believe that its type and 
value are correct.

Should we add a new function that returns a {{TIMESTAMP WITH LOCAL TIME ZONE}}?

> CURRENT_TIMESTAMP has incorrect return type
> -------------------------------------------
>
>                 Key: CALCITE-6045
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6045
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Tanner Clary
>            Priority: Major
>
> When trying to work on CALCITE-6021, I noticed that {{CURRENT_TIMESTAMP}} 
> currently returns type {{TIMESTAMP}} when it should be 
> {{TIMESTAMP_WITH_LOCAL_TIME_ZONE}}.
> After modifying it, I noticed function was returning the time from (UTC - 
> System TZ) hours ago. For example, I am in {{America/Los_Angeles}} and if I 
> called the function at {{2023-10-10 13:28:00 America/Los_Angeles}}, it would 
> return {{2023-10-10 06:28:00 America/Los_Angeles}}. 
> I think this is because the DataContext {{CURRENT_TIMESTAMP}} variable, which 
> is meant to represent milliseconds since epoch UTC, actually has the timezone 
> offset applied in {{CalciteConnectionImpl#DataContextImpl}} 
> [here|https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/jdbc/CalciteConnectionImpl.java#L442].
>  To be clear: it is meant to represent millis since epoch UTC, but instead it 
> is millis since epoch [system tz], as I understand it. 
> Additionally, I believe the {{getString()}} method for timestamps in 
> AvaticaResultSet should behave similarly to 
> [{{SqlFunctions#timestampWithLocalTimezoneToString()}}|https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java#L4021]
>  when dealing with a {{TIMESTAMP WITH LOCAL TIME ZONE}}. Right now, it does 
> not take the timezone into consideration so although it represents the 
> accurate instant in time, it displays differently than 
> {{CAST(CURRENT_TIMESTAMP AS VARCHAR)}}.
> For example, {{SELECT CURRENT_TIMESTAMP, CAST(CURRENT_TIMESTAMP AS 
> VARCHAR)}}, with the correct return type, returns something like:
> {{2023-10-10 13:28:00 |  2023-10-10 06:28:00.000 America/Los_Angeles}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to