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

From drum.lucas@gmail.com
Subject Re: Unique UUID value - PostgreSQL 9.2
Date
Msg-id CAE_gQfUT4EUg75W8fsm+essC_w8GOWHXOMZpKOwnuEKtUmtnRA@mail.gmail.com
Whole thread Raw
In response to Unique UUID value - PostgreSQL 9.2  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
Responses Re: Unique UUID value - PostgreSQL 9.2  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general


On 15 March 2016 at 11:44, Brent Wood <Brent.Wood@niwa.co.nz> wrote:

Not best practice but perhaps viable...


In the target table add a serial datatype column as part of the unique constraint.


Do not populate this column explicitly on insert, but have the db do it for you. It will allocate an incremental (unique) value automatically on insert.


But I think your problem is more fundamental - if you genuinely have duplicate values in a column - there should not be a unique constraint on it. If it should be unique, then you should modify your insert data.



I Can't modify my insert data, because there's a PHP RANDOM CODE that does exactly what I wanna do with the SQL - It generates a random but unique value for the column "code" - So the customer will be able to have duplicates values on that column

Today the PHP is already generating for example:

code_321525694417ad6b5f

So that is linked to another table (I can do that manually no problem)

I just need to know how can I do all of this

pgsql-general by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Re: how to switch old replication Master to new Standby after promoting old Standby
Next
From: "David G. Johnston"
Date:
Subject: Re: Unique UUID value - PostgreSQL 9.2