INSERTing values from usertypes how-to? - Mailing list pgsql-sql

From Mario Splivalo
Subject INSERTing values from usertypes how-to?
Date
Msg-id 1146152613.19362.11.camel@localhost.localdomain
Whole thread Raw
Responses Re: INSERTing values from usertypes how-to?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
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$
DECLAREinsert_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



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Migrating a Database to a new tablespace
Next
From: Richard Huxton
Date:
Subject: Re: any one can help me how to get multiple rows in postgresql