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
---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faqs/FAQ.html