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


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to