3

I've been trying to execute the following sql in postgres 9.6. But I get the error: syntax error at or near "row". Which would be on the line where CREATE AND REPLACE FUNCTION starts.

I've made a sqlfiddle too if you prefer that: 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;
2
  • What is your goal actually ? Commented Aug 29, 2017 at 20:37
  • SQL SERVER! won't have to do that! Commented Aug 29, 2017 at 20:54

1 Answer 1

4

row is a reserved word and you cannot use it as your parameter name. Try this instead

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Such a stupid mistake.. Now I know at least.

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.