Skip site navigation (1) Skip section navigation (2)

plpgsql question: inserting records

From: Brian Hurt <bhurt(at)janestcapital(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: plpgsql question: inserting records
Date: 2007-10-26 17:25:02
Message-ID: 472222EE.3060308@janestcapital.com (view raw or flat)
Thread:
Lists: pgsql-novice
There has to be an easy way to do this and I'm just being stupid and 
missing it.  What I want to do is, in plpgsql, insert a record (of the 
right type) into a table without having to list all the columns of the 
table.  For example, I'd like to do:

CREATE FUNCTION example(id_to_copy INTEGER) RETURNS VOID AS $_$
DECLARE
    t_rec RECORD;
BEGIN
    FOR t_rec IN
        SELECT
            *
        FROM
            table_with_lots_of_columns
        WHERE
            unique_id = id_to_copy
    IN
        t_rec.unique_id := new_unique_id();
        INSERT INTO table_with_lots_of_columns VALUES t_rec; -- or something
    END LOOP;
END
$_$ LANGUAGE plpgsql;

Now, I can do this by listing all the columns from the table, but this 
is annoying.  Is there a way to do this cleaner?


Thanks,
Brian


Responses

pgsql-novice by date

Next:From: Didier Gasser-MorlayDate: 2007-10-26 18:44:38
Subject: Conversion from Sybase
Previous:From: Tom LaneDate: 2007-10-26 00:24:53
Subject: Re: readline library not found

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group