在postgres中使用函数时出现语法错误

时间:2017-08-29 20:24:18

标签: sql postgresql

我一直在尝试在postgres 9.6中执行以下sql。但我收到错误:syntax error at or near "row"。这将是CREATE AND REPLACE FUNCTION开始的行。

如果您愿意,我也制作了一个方形小说:http://sqlfiddle.com/#!17/48a30/1

CREATE TEMPORARY TABLE input (
    id serial, certified boolean
);

CREATE TEMPORARY TABLE tests_person (
  id serial, certified boolean
);

INSERT INTO input (id, certified) VALUES (DEFAULT, True), (DEFAULT, False), (DEFAULT, True), (DEFAULT, False), (DEFAULT, True), (DEFAULT, False);

CREATE OR REPLACE FUNCTION update_record(row input) RETURNS RECORD AS $$
    UPDATE "tests_person"
    SET certified=row.certified
    WHERE certified=row.certified
    RETURNING *
$$ LANGUAGE SQL;

1 个答案:

答案 0 :(得分:4)

row是保留字,您不能将其用作参数名称。试试这个

CREATE OR REPLACE FUNCTION update_record(_input input) RETURNS RECORD AS 
$$
    UPDATE tests_person
    SET certified=_input.certified
    WHERE certified=_input.certified
    RETURNING *
$$ LANGUAGE SQL;