我一直在尝试在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;
答案 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;