Re: parse error for function def - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: parse error for function def
Date
Msg-id 20030717083541.W59122-100000@megazone.bigpanda.com
Whole thread Raw
In response to parse error for function def  (Terence Kearns <terencek@isd.canberra.edu.au>)
List pgsql-sql
On Thu, 17 Jul 2003, Terence Kearns wrote:

> CREATE FUNCTION base.fn_fkey_check(text, text, int4) RETURNS bool AS
> 'DECLARE
> BEGIN
>    RETURN (SELECT count($1) FROM $2 where $1 = $3)::bool;
> END;'
> LANGUAGE 'sql';
>
> produces this error
> ERROR:  parser: parse error at or near "RETURN" at character 20
>
> I'm trying to create a function to use on a trigger to check reference
> to views since pg does not support foreign keys referencing views.

As others have said, the function above is much closer to a plpgsql
function, excepting that you still couldn't use $2 in the from clause
without execute I believe.  In addition, the above isn't going to simulate
a foreign key unless the view is entirely static (if it were that simple,
we'd have implemented it) since changes to the view's base table(s) could
make the constraint be invalid as well.



pgsql-sql by date:

Previous
From: "Richard Jones"
Date:
Subject: Re: NOT and AND problem
Next
From: Gary Stainburn
Date:
Subject: Re: unique value - trigger?