2

I'm trying to create a postgres function which converts the input timestamp to PDT. Here is my code:

CREATE OR REPLACE FUNCTION getPdtTimestamp(inTS TIMESTAMP) RETURNS TIMESTAMP AS $$
DECLARE
    outTS TIMESTAMP;
BEGIN
    SELECT TIMESTAMP with time zone inTS AT TIME ZONE 'PDT' INTO outTS;
    RETURN outTS;
END;
$$ LANGUAGE plpgsql;

The error I get here is:

syntax error at or near "inTS"

My goal is to make a function of a query which looks like this:

SELECT TIMESTAMP with time zone '2012-01-01 12:00:00' AT TIME ZONE 'PDT';
// returns a value

Thanks in advance

1 Answer 1

5

This should work:

CREATE FUNCTION getPdtTimestamp(timestamp) RETURNS TIMESTAMP AS $$ 
    SELECT $1::TIMESTAMP with time zone  AT TIME ZONE 'PDT';
$$ LANGUAGE SQL;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.