Re: Functional dysfunction

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ERIC Lawson - x52010 <eric(at)bioeng(dot)washington(dot)edu>
Cc: pg-novice list <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Functional dysfunction
Date: 2000-07-28 21:03:07
Message-ID: 1506.964818187@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

ERIC Lawson - x52010 <eric(at)bioeng(dot)washington(dot)edu> writes:
> create function matRelat(text)
> returns setof ADR as
> 'select ln from ADR where
> nsrrelat01 ~* \'$1\'::text or
> nsrrelat02 ~* \'$1\'::text or
> nsrrelat03 ~* \'$1\'::text or
> nsrrelat04 ~* \'$1\'::text;'
> language 'sql';

Seems to me you want "returns setof TEXT" or whatever the datatype of ln
is. "setof ADR" implies it returns the whole tuple (that would be
appropriate if you wanted "select * from ADR where ...").

Beware that functions returning sets are not all that well supported;
they work in simple examples like "select function(...)" but you can't
really combine them in expressions.

Have you thought about a view? Perhaps

create view v1 as select ln, nsrrelat01 || ' ' || nsrrelat02 || ' ' ||
nsrrelat03 || ' ' || nsrrelat04 as nsrrelat;

and then

select ln from v1 where nsrrelat ~* 'foo';

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message ERIC Lawson - x52010 2000-07-28 21:43:18 Re: Functional dysfunction
Previous Message ERIC Lawson - x52010 2000-07-28 19:09:09 Functional dysfunction