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

Re: insert into test_b (select * from test_a) with different column order

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Ole Tange <ole(at)tange(dot)dk>
Cc: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: insert into test_b (select * from test_a) with different column order
Date: 2010-03-30 10:42:41
Message-ID: e4edc9361003300342y2f097a8fl1de0f9b9be4f78a3@mail.gmail.com (view raw or flat)
Thread:
Lists: 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

In response to

pgsql-general by date

Next:From: dipti shahDate: 2010-03-30 11:05:27
Subject: Get the list of permissions on schema for current user
Previous:From: Alban HertroysDate: 2010-03-30 10:27:46
Subject: Re: How to implement word wrap

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