X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 47E5AD8377 for ; Thu, 3 Nov 2005 11:14:13 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 30060-08 for ; Thu, 3 Nov 2005 15:14:09 +0000 (GMT) Received: from smtp-gw-cl-d.dmv.com (smtp-gw-cl-d.dmv.com [216.240.97.42]) by svr1.postgresql.org (Postfix) with ESMTP id 9E5EED8258 for ; Thu, 3 Nov 2005 11:14:11 -0400 (AST) Received: from mail-gw-cl-a.dmv.com (mail-gw-cl-a.dmv.com [216.240.97.38]) by smtp-gw-cl-d.dmv.com (8.12.10/8.12.10) with ESMTP id jA3FEEf5090973 for ; Thu, 3 Nov 2005 10:14:14 -0500 (EST) (envelope-from sven@dmv.com) Received: from lanshark.dmv.com (lanshark.dmv.com [216.240.97.46]) by mail-gw-cl-a.dmv.com (8.12.9/8.12.9) with ESMTP id jA3FEDLR008362 for ; Thu, 3 Nov 2005 10:14:13 -0500 (EST) (envelope-from sven@dmv.com) Subject: Function with table%ROWTYPE globbing From: Sven Willenberger To: pgsql-performance@postgresql.org Content-Type: text/plain Date: Thu, 03 Nov 2005 10:14:15 -0500 Message-Id: <1131030856.9769.3.camel@lanshark.dmv.com> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.48 on 216.240.97.42 X-Scanned-By: MIMEDefang 2.48 on 216.240.97.38 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.527 required=5 tests=[AWL=-0.352, DNS_FROM_RFC_WHOIS=0.879] X-Spam-Score: 0.527 X-Spam-Level: X-Archive-Number: 200511/42 X-Sequence-Number: 15299 Postgresql 8.0.4 using plpgsql The basic function is set up as: CREATE FUNCTION add_data(t_row mytable) RETURNS VOID AS $func$ DECLARE newtable text; thesql text; BEGIN INSERT INTO newtable thename from mytable where lookup.id = t_row.id; thesql := 'INSERT INTO ' || newtable || VALUES (' || t_row.* ')'; EXECUTE thesql; RETURN; END; $func$ LANGUAGE plpgsql VOLATILE; SELECT add_data(t.*) FROM mytable t where .... ERROR: column "*" not found in data type mytable Now I have tried to drop the * but then there is no concatenation function to join text to a table%ROWTYPE. So my question is how can I make this dynamic insert statement without listing out every t_row.colname? Or, alternatively, is there a better way to parse out each row of a table into subtables based on a column value? Sven