pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephan Szabo <sszabo@megazone.bigpanda.com>
To: Terence Kearns <terencek@isd.canberra.edu.au>
Cc: pgsql-sql@postgresql.org
Subject: Re: parse error for function def
Date: Thu, 17 Jul 2003 08:39:17 -0700 (PDT)
Message-ID: <20030717083541.W59122-100000@megazone.bigpanda.com> (raw)
In-Reply-To: <3F167E9D.2090709@cts.canberra.edu.au>


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.




view thread (5+ messages)  latest in thread

Message-ID: <20030717083541.W59122-100000@megazone.bigpanda.com>
Permalink:  ../20030717083541.W59122-100000@megazone.bigpanda.com/
Also on:    postgresql.org/message-id/20030717083541.W59122-100000@megazone.bigpanda.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sszabo@megazone.bigpanda.com, terencek@isd.canberra.edu.au
  Subject: Re: parse error for function def
  In-Reply-To: <20030717083541.W59122-100000@megazone.bigpanda.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox