pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marinos Yannikos <mjy@geizhals.at>
To: pgsql-sql@postgresql.org
Subject: plpgsql: PERFORM vs. SELECT INTO (PERFORM not setting FOUND variable?)
Date: Mon, 25 Oct 2004 21:44:49 +0200
Message-ID: <417D57B1.8010507@geizhals.at> (raw)

Hi,

I'm probably misintepreting the documented equivalence of PERFORM and 
SELECT INTO as far as the special variable FOUND is concerned, but the 
following 2 definitions do not seem to produce the same result.

create table blup ( t1 text, t2 text );

create function blup_unique2 (text,text) returns boolean as 'begin 
perform (select 1 from blup where t1=$1 or t1=$2 or t2=$1 or t2=$2 or 
$1=$2 limit 1); return NOT FOUND; end' LANGUAGE plpgsql;

create function blup_unique3 (text,text) returns boolean as 'declare x 
record; begin select into x 1 from blup where t1=$1 or t1=$2 or t2=$1 or 
t2=$2 or $1=$2 limit 1; return NOT FOUND; end' LANGUAGE plpgsql;

The first will always produce false, i.e. apparently the subquery used 
by PERFORM will not set the variable FOUND as expected. Is this correct?

(btw.: I'm trying a few ways to ensure that all values in both t1 and t2 
are unique:
alter table blup add constraint check (blup_unique3(t1,t2));
  - perhaps there are more elegant ways, any suggestions?)

Regards,
  Marinos




view thread (3+ messages)  latest in thread

Message-ID: <417D57B1.8010507@geizhals.at>
Permalink:  ../417D57B1.8010507@geizhals.at/
Also on:    postgresql.org/message-id/417D57B1.8010507@geizhals.at

 · 

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: mjy@geizhals.at
  Subject: Re: plpgsql: PERFORM vs. SELECT INTO (PERFORM not setting FOUND variable?)
  In-Reply-To: <417D57B1.8010507@geizhals.at>

* 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