postgresql - PgSQL turning day-of-year back into date -
i trying determine how turn day-of-year date in pgsql. when this
select date '2013-01-01' + interval '53 days'
i timestamp:
"2013-02-23 00:00:00"
so how come when of following
select extract(date (date '2013-01-01' + interval '53 days')) select extract(date (select date '2013-01-01' + interval '53 days'))
i "error: timestamp units "date" not recognized"? besides why, how can want, date portion of result of original operation?
use
select (date '2013-01-01' + interval '53 days')::date
or
select cast(date '2013-01-01' + interval '53 days' date)
postgresql's standard sql function "extract()" will operate on timestamps, a) "date" isn't valid argument extract(), , b) returns subfields, not collection of subfields. conceptually, date consists of collection of 3 subfields: year, month, , day.
select extract(year current_timestamp), extract(month current_timestamp), extract(day current_timestamp), -- concatenate , cast type "date". (extract(year current_timestamp) || '-' || extract(month current_timestamp) || '-' || extract(day current_timestamp))::date
Comments
Post a Comment