Re: Unique UUID value - PostgreSQL 9.2

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unique UUID value - PostgreSQL 9.2
Date: 2016-03-14 21:44:19
Message-ID: CAKFQuwbtG1jTBcX10mnyyPo-_rjNE92SkL=4CeOkOdC6fTY=8g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Mar 14, 2016 at 2:37 PM, drum(dot)lucas(at)gmail(dot)com <drum(dot)lucas(at)gmail(dot)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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message James Keener 2016-03-14 21:46:03 Re: Unique UUID value - PostgreSQL 9.2
Previous Message James Keener 2016-03-14 21:44:09 Re: BDR