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;
Kamran
8531 gold badge8 silver badges20 bronze badges
asked Aug 29, 2017 at 20:24
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;
answered Aug 29, 2017 at 20:38
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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.