X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E2C8B11F624A for ; Thu, 27 Apr 2006 13:09:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 54946-03 for ; Thu, 27 Apr 2006 13:09:29 -0300 (ADT) X-Greylist: delayed 00:25:07.899011 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id AF09B11F6AEE for ; Thu, 27 Apr 2006 13:09:28 -0300 (ADT) Received: from ls405.htnet.hr (ls405.t-com.hr [195.29.150.135]) by svr4.postgresql.org (Postfix) with ESMTP id C20725B1152 for ; Thu, 27 Apr 2006 15:44:19 +0000 (GMT) Received: from ls401.t-com.hr (ls401.t-com.hr [195.29.150.236]) by ls405.htnet.hr (Postfix) with ESMTP id 525861474A3 for ; Thu, 27 Apr 2006 17:44:15 +0200 (CEST) Received: from ls401.t-com.hr (localhost.localdomain [127.0.0.1]) by ls401.t-com.hr (Qmlai) with ESMTP id 4F53CE38E4 for ; Thu, 27 Apr 2006 17:44:15 +0200 (CEST) X-Envelope-Sender: mario.splivalo@mobart.hr Received: from 83-131-55-80.adsl.net.t-com.hr (83-131-55-80.adsl.net.t-com.hr [83.131.55.80]) by ls401.t-com.hr (Qmlai) with ESMTP id EF0AA38032 for ; Thu, 27 Apr 2006 17:44:14 +0200 (CEST) Subject: INSERTing values from usertypes how-to? From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: Mob-Art Date: Thu, 27 Apr 2006 17:43:32 +0200 Message-Id: <1146152613.19362.11.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/193 X-Sequence-Number: 25002 Comming back after SELECTing into usertypes, is there a nice way to insert data into table from usertype, in a nice way? For instance, I have table like this: CREATE TABLE tblA ( id int4, key varchar, value varchar ) Then, in my function, I do this: CREATE FUNCTION testInsert() RETURNS void AS $BODY$ DECLARE insert_tblA tblA; insert_tblA.id = get_next_id_or_something(); insert_tblA.key = get_user_key_or_something(); insert_tblA.value = get_some_value(); INSERT INTO tblA ( id, key, value) VALUES ( insert_tblA.id, insert_tblA.key, insert_tblA.value ); END $BODY$ LANGUAGE 'plpgsql'; Now, in this particular example it seems stupid first to populate usertype and then insert the data from it to the tblA table, but in my actuall function that makes sense (the function is quite large for posting here). Now, since sometimes I have 30 columns in a table, I tried to find a way to simply 'pour' the usertype into the table. I tried something like: INSERT INTO tblA (insert_tblaA); but postgres complains (and I guess I expeted that) with an error saying that tblA.id is of type int4, and I'm trying to insert value of type tblA. So, is there a way to map all those type-members in a way so that one could easily INSERT those into table? Mario