Re: Unique UUID value - PostgreSQL 9.2 - Mailing list pgsql-general

From David G. Johnston
Subject Re: Unique UUID value - PostgreSQL 9.2
Date
Msg-id CAKFQuwbtG1jTBcX10mnyyPo-_rjNE92SkL=4CeOkOdC6fTY=8g@mail.gmail.com
Whole thread Raw
In response to Re: Unique UUID value - PostgreSQL 9.2  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
List pgsql-general
On Mon, Mar 14, 2016 at 2:37 PM, drum.lucas@gmail.com <drum.lucas@gmail.com> wrote:


I want to import data from table A to table B, but when doing it the column "code" on table B has to have some unique random data.

I could use UUID like:
insert into "TB" ("Id", "Title") values (uuid_generate_v4(), '111'); 

but I'm doing:
INSERT INTO tableb (SELECT * FROM TABLEA)

So, how to use UUID using the SELECT above?



​By explicitly listing column names instead of using "*" and then instead of copying a column from A to B you omit the column from A and replace it with a function call.​

​INSERT INTO tableb ("Id", "Title")
SELECT uuid_generate_v4(), "Title"
FROM tablea​;

David J.

pgsql-general by date:

Previous
From: James Keener
Date:
Subject: Re: BDR
Next
From: James Keener
Date:
Subject: Re: Unique UUID value - PostgreSQL 9.2