I have a timestamp attribute in a table on which I want to place a condition in a sql query where the condition value is a unix timestamp (i.e. numeric long value).
[...] table.timestampattr > 6456454654 [...]
How can I do this?
You can use extract(epoch from ...) to get a Unix timestamp from any of the PostgreSQL time and date types (see Date/Time functions in manual).
So your query fragment could be written:
[...] extract(epoch from table.timestampattr) > 6456454654 [...]
Alternatively, the to_timestamp function performs the opposite conversion, so you could also write:
[...] table.timestampattr > to_timestamp(6456454654) [...]
to_timestamp is defined as IMMUTABLE, so the query planner should know to run it once and cache the result.immutable attribute of the function that makes this possible, not some internal magic. A user-defined function (for instance, for converting an MS "ticks" value) would get the same performance benefit if it was defined as immutable, but would be evaluated for every row if it was not.to_timestamp accepts a float, so you can add a decimal point and get the value you were after: select to_timestamp(1360417525.156).