Re: Importing data w/ Unix timestamp - Mailing list pgsql-general

From Tom Lane
Subject Re: Importing data w/ Unix timestamp
Date
Msg-id 1155.962305441@sss.pgh.pa.us
Whole thread Raw
In response to Re: Importing data w/ Unix timestamp  (Thomas Lockhart <lockhart@alumni.caltech.edu>)
List pgsql-general
Thomas Lockhart <lockhart@alumni.caltech.edu> writes:
> Another side comment: afaik an explicit conversion to abstime is not
> required to go from Unix time to timestamp. So
>   insert into RealTable select uname, timestamp(timeinAsInt4),
>                                duration, etc from TempTable;
> should be equivalent.

Ah, right, that does work.  Just to drift a little further off topic,
the locutions
        timeinAsInt4::timestamp
        cast (timeinAsInt4 as timestamp)
do not work, because in those cases the parser expects to find a
one-step conversion method, and there isn't one --- at least not in
the standard set of Postgres functions.  The function-call syntax works
because there is a function timestamp(abstime) and the parser figures
out it can resolve the ambiguous function name timestamp() as that
function if it first applies int4-to-abstime coercion, which it knows
how to do.

In short: you can get a two-step type conversion from the function call
notation, but only one-step from cast notation.

            regards, tom lane

pgsql-general by date:

Previous
From: "Mitch Vincent"
Date:
Subject: Trigger question.. (Heaptuple struct)
Next
From: Tom Lane
Date:
Subject: Re: pg_dump/load quoting.