I am a super noob in postgresql. But I need to define a func that would map: int --> datetime
After reading documentation I've come up with this:
CREATE FUNCTION fut(num integer) RETURNS datetime
-- convert a UNIX time integer into the datetime timestamp
AS $$ select timestamp 'epoch'+interval '1 second'*num; $$
LANGUAGE plpgsql;
select fut(500);
But it returns
The cursor is not located inside a statement!
Could you please point me to what I am doing wrong here?
As far as I knew Redshift doesn't even permit user-defined functions. Yeah: http://docs.aws.amazon.com/redshift/latest/dg/c_unsupported-postgresql-features.html : User-defined functions and stored procedures. So I think you're plain out of luck.
A search for Redshift epoch to timestamp or redshift
to_timestamp
finds that lots of other people have looked into this already:etc.
The most sensible answers are those that rely on:
which is what you appear to be already doing. This the best you are going to get, because Redshift does not support user-defined functions.