GithubHelp home page GithubHelp logo

Comments (5)

snoyberg avatar snoyberg commented on August 16, 2024

I just tried using now() as the default value, and it appeared to work correctly:

postgres=# create table tmp(x INTEGER,foo timestamp with time zone default now());
CREATE TABLE
postgres=# insert into tmp(x) values(0);
INSERT 0 1
postgres=# select * from tmp;
 x |              foo              
---+-------------------------------
 0 | 2014-07-31 14:05:58.407412+03
(1 row)

And in fact, I ran the command at 14:05 in my current time zone (UTC+3). Can you clarify how you determined the now() was not a sufficient default?

from yesodweb.com-content.

bholst avatar bholst commented on August 16, 2024

Well, it works correctly and does what you expect when having a column with time zone. However, yesod (or persistent) creates a column without time zone for the type UTCTime.

test=# create table tmp(x INTEGER,foo timestamp without time zone default now());
CREATE TABLE
test=# insert into tmp(x) values(0);
INSERT 0 1
test=# select * from tmp;
 x |            foo             
---+----------------------------
 0 | 2014-07-31 15:07:31.461828
(1 row)

I ran this command at 15:07 in my current time zone (UTC+2). So this is not the UTC time in the table.
With now() at time zone 'utc' everything works as expected and I get

test=# select * from tmp;
 x |            foo             
---+----------------------------
 0 | 2014-07-31 13:07:31.461828
(1 row)

In contrast to that, a time from getCurrentTime in Haskell is always printed as UTC and persistent insert this into the database like that. Again, if you use a table with without timestamp as the default configuration does, it inserts the UTC time with dropping the time zone.

> getCurrentTime >>= print
2014-07-31 13:12:58.708879 UTC

from yesodweb.com-content.

snoyberg avatar snoyberg commented on August 16, 2024

Ahh, right, I forgot about that. We're about to release persistent 2.0, which will fix this bug. In the meanwhile, you can use ZonedTime instead of UTCTime.

from yesodweb.com-content.

bholst avatar bholst commented on August 16, 2024

Thanks!
Just to make sure I understood you correctly:
persistent 2.0 will use timestamp with time zone by default?

from yesodweb.com-content.

snoyberg avatar snoyberg commented on August 16, 2024

Yes.

from yesodweb.com-content.

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.