lpsmith / postgresql-simple

Mid-level client library for accessing PostgreSQL from Haskell
Other
206 stars 71 forks source link

Lose TZ in timestamptz #264

Closed YurovRuslan closed 6 years ago

YurovRuslan commented 6 years ago

I have a table which creates like:

create_table = [sql|
CREATE TABLE IF NOT EXISTS sometable
    ( ...
    , time TIMESTAMP WITH TIME ZONE NOT NULL
    ...
    );
|]

Then I create someschema from sometable. Field time goes via psql functions: tstzrange, MAX and time_bucket(tsdb)

Then I have a query to this table:

data <- query conn Sql.selectFromSomeSchema (timeZoneName $ zonedTimeZone from, ...)

Sql query looks like:

selectFromSomeSchema = [sql|
SELECT          
    timezone(?, LOWER(range))
    , timezone(?, UPPER(range))
    , CAST(EXTRACT(EPOCH FROM (UPPER(range) - LOWER(range))) AS INTEGER) FROM someschema
WHERE
    ...
|]

And I have an error:

"Incompatible {errSQLType = \"timestamp\", errSQLTableOid = Nothing, errSQLField = \"timezone\", errHaskellType = \"ZonedTime\", errMessage = \"\"}"
lpsmith commented 6 years ago

Timestamptz does not store the timezone on a per-value or per-column basis. You should read the documentation I wrote in the Time module.

lpsmith commented 6 years ago

Also, you might be interested in reading the discussion of issue #69.