Re: pl/pgsql docs 37.4.3. Row Types -- how do I use this function?

From: "Lee Harr" <missive(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: pl/pgsql docs 37.4.3. Row Types -- how do I use this function?
Date: 2004-01-24 23:19:39
Message-ID: BAY2-F76yNtqMk7LiHd0001c67a@hotmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>>I am following along with the pl/pgsql docs here:
>>http://www.postgresql.org/docs/current/static/plpgsql-declarations.html
>
>>Now, how do I call the function?
>
>I believe you want
>
>select use_two_tables(tablename.*) from tablename;
>
>"foo.*" is the locution for referring to the whole-row value coming from
>table foo in a select.
>

A ha! That's the one!
Here is a complete working example for those playing along at home...

CREATE TABLE ta1(
f1 text,
f2 text,
f3 text,
f4 text,
f5 text,
f6 text,
f7 text
);
CREATE TABLE ta2(
f1 text,
f2 text,
f3 text,
f4 text,
f5 text,
f6 text,
f7 text
);
insert into ta1 values ('a', 'b', 'c', 'd', 'e', 'f', 'g');
insert into ta1 values ('aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg');
insert into ta1 values ('aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff', 'ggg');
insert into ta2 values ('z', 'y', 'x', 'w', 'v', 'u', 't');
insert into ta2 values ('zz', 'yy', 'xx', 'ww', 'vv', 'uu', 'tt');

CREATE or REPLACE FUNCTION use_two_tables(ta1) RETURNS text AS '
DECLARE
in_t ALIAS FOR $1;
use_t ta2%ROWTYPE;
BEGIN
SELECT * INTO use_t FROM ta2 WHERE f1 = ''z'';
RETURN in_t.f1 || use_t.f3 || in_t.f5 || use_t.f7;
END;
' LANGUAGE plpgsql;

# select use_two_tables(ta1.*) from ta1;
use_two_tables
----------------
axet
aaxeet
aaaxeeet
(3 rows)

Thank you for your help.

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2004-01-25 00:35:43 Re: Log_statement behaviour a little misleading?
Previous Message Eric Ridge 2004-01-24 21:19:23 Re: Touch row ?