質問

Trying to port a T-SQL CTE to PostgreSQL. In T-SQL cast(0 as datetime) returns

1900-01-01 00:00:00.000

Is there an equivalent 'side-effect' in pg, to get Day One of the epoch?

EDIT:

to_timestamp(0) on my machine --returns 1969-12-31 19:00:00-05. 

select '1970-01-01 00:00:00'::timestamptz --returns 1970-01-01 00:00:00-05
select '1970-01-01 00:00:00'::timestamp --returns 1/1/1970 which is the same as
select '1970-01-01 00:00:00'::date    -- returns 1/1/1970

I expected the cast to timestamp to return 1970-01-01 00:00:00, that is, removing the timezone but not the time.

役に立ちましたか?

解決

If by epoch you mean 1 Jan 1970 00:00 (not 1900), you can do:

to_timestamp(0)

To get the time in a particular timezone, try:

to_timestamp(0) AT TIME ZONE 'GMT'

or

to_timestamp(0) AT TIME ZONE 'UTC'
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top