0

I wrote this query in PostgreSQL:

CREATE OR REPLACE FUNCTION pippo() RETURNS TRIGGER AS $$
BEGIN
  CHECK (NOT EXISTS (SELECT * FROM padre WHERE cod_fis NOT IN (SELECT padre FROM paternita)));
END;
$$ LANGUAGE plpgsql;

It returns:

Syntax error at or near CHECK.

I wrote this code because I have to realize a 1..n link between two tables.

6
  • What is the desired results of your function? Commented Dec 1, 2014 at 19:03
  • @Andreas: Maybe you can start by telling him where his syntax error is. Commented Dec 1, 2014 at 19:06
  • Can you post the table structures and some sample records. It's hard to see what you're trying to do... Commented Dec 1, 2014 at 19:09
  • @RobertHarvey, his syntax error is at or near CHECK. We already know that. Commented Dec 1, 2014 at 19:09
  • What is CHECK(...)? AFAIK it is not a function built into postgresql. Commented Dec 1, 2014 at 19:19

1 Answer 1

1

You can't use CHECK here. CHECK is for table and column constraints.

Two further notes:

  • If this is supposed to be a statement level constraint trigger, I'm guessing you're actually looking for IF ... THEN RAISE EXCEPTION 'message'; END IF;
    (If not, you may want to expand and clarify what you're trying to do.)
  • The function should return NEW, OLD or NULL.
Sign up to request clarification or add additional context in comments.

Comments

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.