Search code examples
postgresqlplpgsqlrowtype

Insert %rowtype data into another table - plpgsql / Postgres


I have one table called empl, and have another table new_empl with the same columns and definition with empl. Is it possible to insert records from v_record in new_empl using the following code ?

DECLARE
   v_record empl%rowtype;
BEGIN 
   Insert into new_empl values v_record;
END;

There are too many columns in empl table and I want to avoid listing them.


Solution

  • The above snippet would work for Oracle, but for Postgres/pgplsql, the following snippet works like a charm:

    DECLARE
       v_record empl%rowtype;
    BEGIN 
       Insert into new_empl values (v_record.*);
    END;