Re: parse error for function def

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Terence Kearns <terencek(at)isd(dot)canberra(dot)edu(dot)au>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: parse error for function def
Date: 2003-07-17 15:39:17
Message-ID: 20030717083541.W59122-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gary Stainburn 2003-07-17 15:49:25 Re: unique value - trigger?
Previous Message Richard Jones 2003-07-17 15:09:45 Re: NOT and AND problem