X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id 64A2FCCA54 for ; Thu, 17 Jul 2003 15:38:59 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 62459-02 for ; Thu, 17 Jul 2003 15:39:19 +0000 (GMT) Received: from megazone.bigpanda.com (unknown [66.180.233.26]) by svr1.postgresql.org (Postfix) with ESMTP id 2D6E0CCA46 for ; Thu, 17 Jul 2003 12:38:48 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id CE70CD671; Thu, 17 Jul 2003 08:39:17 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id C41715C0F; Thu, 17 Jul 2003 08:39:17 -0700 (PDT) Date: Thu, 17 Jul 2003 08:39:17 -0700 (PDT) From: Stephan Szabo To: Terence Kearns Cc: Subject: Re: parse error for function def In-Reply-To: <3F167E9D.2090709@cts.canberra.edu.au> Message-ID: <20030717083541.W59122-100000@megazone.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/227 X-Sequence-Number: 14341 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.