2

我正在尝试创建一个将输入时间戳转换为 PDT 的 postgres 函数。这是我的代码:

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

提前致谢

4

1 回答 1

4

这应该有效:

CREATE FUNCTION getPdtTimestamp(timestamp) RETURNS TIMESTAMP AS $$ 
    SELECT $1::TIMESTAMP with time zone  AT TIME ZONE 'PDT';
$$ LANGUAGE SQL;
于 2013-06-19T06:35:34.813 回答