Giter Club home page Giter Club logo

Comments (14)

hawkfish avatar hawkfish commented on June 2, 2024

What time zone are you running the queries in?

from duckdb.

manticore-projects avatar manticore-projects commented on June 2, 2024

Bangkok/Thailand - UTC+7
But why would that matter for date trunc please?

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

Also, DATE_TRUNC always returns TIMESTAMP_TZ - this matches the behaviour of Postgres:

hawkfish=# set timezone='US/Pacific';
SET
hawkfish=# select date_trunc('year', '2015-05-08T23:39:20.123-07:00'::TIMESTAMPTZ);
       date_trunc       
------------------------
 2015-01-01 00:00:00-08

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

Bangkok/Thailand - UTC+7 But why would that matter for date trunc please?

I don't know, but it's part of the environment that need for reproducing TZ issues. (I've even had issues where the calendar was not Gregorian...)

from duckdb.

manticore-projects avatar manticore-projects commented on June 2, 2024

Also, DATE_TRUNC always returns TIMESTAMP_TZ - this matches the behaviour of Postgres:

SELECT TIMESTAMP '2015-05-08T23:39:20.123-07:00' AS "DATE1",
       typeof(DATE_TRUNC('YEAR', "DATE1")) AS "TRUNCATED TO YEAR",
       typeof(DATE_TRUNC('MONTH', "DATE1")) AS "TRUNCATED TO MONTH",
       typeof(DATE_TRUNC('DAY', "DATE1")) AS "TRUNCATED TO DAY";

/*
┌───────────────────┬───────────────────┬────────────────────┬──────────────────┐
│ DATE1             │ TRUNCATED TO YEAR │ TRUNCATED TO MONTH │ TRUNCATED TO DAY │
├───────────────────┼───────────────────┼────────────────────┼──────────────────┤
│ 09/05/2015, 06:39 │ DATE              │ DATE               │ DATE             │
└───────────────────┴───────────────────┴────────────────────┴──────────────────┘
*/


But not for TIMESTAMP?

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

Do you mean Asia/Bangkok?

D from duckdb_settings() where name = 'TimeZone';
name value description input_type scope
TimeZone America/Los_Angeles The current time zone VARCHAR GLOBAL

from duckdb.

manticore-projects avatar manticore-projects commented on June 2, 2024

Do you mean Asia/Bangkok?

D from duckdb_settings() where name = 'TimeZone';

name value description input_type scope
TimeZone America/Los_Angeles The current time zone VARCHAR GLOBAL

Yes, sorry, I was on a call in parallel.
Thank you for helping, I appreciate!

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

Ah it looks like we have tweaked the binder for TIMESTAMP and this does not match PG. I think the reason we didn't is that with TSTZ truncating to a DATE depends on the TZ, which could cause problems (if the date was stored and then cast back to TSTZ in a different TZ there would be data corruption).

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

I can't reproduce your problem on 0.10.2, but the display of your values is a bit concerning. 2014-12-31T17:00Z is not what we usually display? It looks like you may not have ICU loaded?

D from duckdb_extensions() where extension_name ='icu';
extension_name loaded installed install_path description aliases extension_version
icu true true (BUILT-IN) Adds support for time zones and collations using the ICU library []

from duckdb.

manticore-projects avatar manticore-projects commented on June 2, 2024

My output is from out own JDBC Database browser, not from DuckDB2 directly.
I use it for simplified ASCII copy'n paste.

ICU is available:

┌────────────────┬────────┬───────────┬──────────────┬──────────────────────────────────────────────────────────────────┬─────────┬───────────────────┐
│ extension_name │ loaded │ installed │ install_path │ description                                                      │ aliases │ extension_version │
├────────────────┼────────┼───────────┼──────────────┼──────────────────────────────────────────────────────────────────┼─────────┼───────────────────┤
│ icu            │ true   │ true      │ (BUILT-IN)   │ Adds support for time zones and collations using the ICU library │ []      │                   │
└────────────────┴────────┴───────────┴──────────────┴──────────────────────────────────────────────────────────────────┴─────────┴───────────────────┘

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

My output is from out own JDBC Database browser, not from DuckDB2 directly. I use it for simplified ASCII copy'n paste.

Ah that's the confusion then. The results you are getting are the timestamps truncated to the start of the year in your time zone, but displayed in UTC.

from duckdb.

manticore-projects avatar manticore-projects commented on June 2, 2024

I am honestly confused here. In my simple world, a DATE TRUNC would return a DATE which is not sensitive to a Time Zone because Date has no time. So when applying DATE TRUNC on a TIMESTAMPTZ I would have expected 1) translation to UTC TIMESTAMP and then truncating the time.

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

Sadly we do not live in a simple world where time is concerned!

But dates are sensitive to time zone: A date is a range of instants. But to get the behaviour you want, just add a cast to DATE:

D select date_trunc('year', '2015-05-08T23:39:20.123-07:00'::TIMESTAMPTZ)::DATE y;
y
2015-01-01

from duckdb.

hawkfish avatar hawkfish commented on June 2, 2024

Think this got sorted?

from duckdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.