From: | Mario Splivalo <mario(dot)splivalo(at)mobart(dot)hr> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | INSERTing values from usertypes how-to? |
Date: | 2006-04-27 15:43:32 |
Message-ID: | 1146152613.19362.11.camel@localhost.localdomain |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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$
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
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2006-04-27 16:34:25 | Re: INSERTing values from usertypes how-to? |
Previous Message | Tom Lane | 2006-04-27 15:06:09 | Re: Migrating a Database to a new tablespace |