Re: insert into test_b (select * from test_a) with different column order - Mailing list pgsql-general

From Szymon Guz
Subject Re: insert into test_b (select * from test_a) with different column order
Date
Msg-id e4edc9361003300342y2f097a8fl1de0f9b9be4f78a3@mail.gmail.com
Whole thread Raw
In response to Re: insert into test_b (select * from test_a) with different column order  (Ole Tange <ole@tange.dk>)
List pgsql-general

This will not work for me as I do not know in advance what columns
exist in test_a or test_b. I only know they are called the same (and
have the same datatypes).

So is there a dynamic way in which I can generate the INSERT statement
given the name of the two tables?


You can write a procedure e.g. in pl/pgsql that will check the column names from a system view like pg_* (I don't remember now) and create the query from the column names and some sql keywords into a text variable. Later you can use EXECUTE for executing such a query from a variable.
 

regards
Szymon Guz

pgsql-general by date:

Previous
From: "Davor J."
Date:
Subject: Emphasizing "current item" in subclass of QAbstractItemView
Next
From: dipti shah
Date:
Subject: Get the list of permissions on schema for current user