Re: to_timestamp alternatives - Mailing list pgsql-general

From gkhan
Subject Re: to_timestamp alternatives
Date
Msg-id 1451603134115-5879753.post@n5.nabble.com
Whole thread Raw
In response to Re: to_timestamp alternatives  (gkhan <drjohnpayne@gmail.com>)
Responses Re: to_timestamp alternatives  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
Re: to_timestamp alternatives  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
Follow-up:

My initial question was about oddly-formatted date/times.  The suggested
solution of casting directly to timestamp with ::timestamp is not as
flexible as the to_timestamp function that I was trying to avoid.  For
example, this fails because of the day-before-month format:

SELECT ('18.09.2015 18:01:40')::timestamp
--ERROR: date/time field value out of range

whereas this works, but results in a timestamp *with* time zone that makes
assumptions about daylight savings times:
SELECT to_timestamp('18.09.2015 18:01:40','DD.MM.YYYY HH24:MI:SS')

I ended up with this simple solution, which does what I wanted to and avoids
time zones:
SELECT (to_date('18.09.2015','DD.MM.YYYY') ||' '||'18:01:40')::timestamp

Adrian: thanks for your observation about wildlife-human interactions --
that is a useful reminder since I'll be looking at traffic patterns.



--
View this message in context: http://postgresql.nabble.com/to-timestamp-alternatives-tp5879723p5879753.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: to_timestamp alternatives
Next
From: Jim Nasby
Date:
Subject: Re: to_timestamp alternatives