Re: how to select one column into another in same table?

From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: "J(dot)V(dot)" <jvsrvcs(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: how to select one column into another in same table?
Date: 2011-10-04 19:09:21
Message-ID: CAOR=d=14GyurSZ0e-j5O7ordmrvNT1F=qN853VR0vdasz2d8WQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Oct 4, 2011 at 12:24 PM, J.V. <jvsrvcs(at)gmail(dot)com> wrote:
> Currently I can select one column into another with two statements:
>
>    alter table <table_name> add column id_old int;
>    update <table_name> set id_old = id;
>
> Is there a way to do this in one statement with a select into?  I have tried
> various select statements but want the new column (with the same data) to be
> in the same table and to have it execute much more quickly that the two
> statements currently do.

Do you need another column or do you just want to alter a column that
already exists? If so you can alter a column from one type to another
and throw a using clause at it to convert the data in some way. I
think we need to know a bit better what you're trying to do.,

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2011-10-04 19:12:15 Re: fail: alter table <table_name> NOCHECK CONSTRAINT ALL;
Previous Message J.V. 2011-10-04 18:24:34 how to select one column into another in same table?