我正在尝试创建一个postgres函数,将输入时间戳转换为PDT。这是我的代码:
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;
我得到的错误是:
syntax error at or near "inTS"
我的目标是创建一个如下所示的查询函数:
SELECT TIMESTAMP with time zone '2012-01-01 12:00:00' AT TIME ZONE 'PDT';
// returns a value
提前致谢
答案 0 :(得分:3)
这应该有效:
CREATE FUNCTION getPdtTimestamp(timestamp) RETURNS TIMESTAMP AS $$
SELECT $1::TIMESTAMP with time zone AT TIME ZONE 'PDT';
$$ LANGUAGE SQL;