Re: UUID column as pimrary key?

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Radosław Smogura <rsmogura(at)softperience(dot)eu>
Cc: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>, Dennis Gearon <gearond(at)sbcglobal(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: UUID column as pimrary key?
Date: 2011-01-05 14:34:00
Message-ID: AANLkTim2UJKr1foZBP5a=C5DgL-nOA6YigDNDNoZqznd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 5 January 2011 15:28, Radosław Smogura <rsmogura(at)softperience(dot)eu> wrote:

> On Wed, 05 Jan 2011 21:50:11 +1100, Craig Ringer <
> craig(at)postnewspapers(dot)com(dot)au> wrote:
>
>> On 01/05/2011 07:31 PM, Radosław Smogura wrote:
>>
>> * you have your id, before executing query, (in contrast to all this
>>> autoincrement) so you may put it in dependant rows
>>>
>>
>> Do you mean that with a UUID, you don't need to talk to the database
>> at all, you can generate an ID with no interaction with / involvement
>> with the database at all? Because other than that, there's not much
>> difference in how you normally work with them.
>>
>>
>> With a sequence, you might:
>>
>> CREATE SEQUENCE x_id_seq;
>> CREATE TABLE x (
>> id integer PRIMIARY KEY DEFAULT nextval('x_id_seq'),
>> y integer
>> );
>> INSERT INTO x(y) VALUES (1);
>>
>> I mean situation, when You create e.g. in one transaction, book and
> chapters, in some way You need retrieve book's id, by returning clause of
> insert, or by obtaining id form sequence.
> It's simpler to write:
> book_id = new uuid();
> insert into book values(book_id,....);
> insert into chapters values(new uuid(), book_id, ...);
> isn't it?
>
>
>
For me it is simpler just to write this:

bookid = insert into books(...) values(...) returning book_id;
insert into chapters(book_id, ...) values( bookid, ...);

but it's a matter of taste, I think.

regards
Szymon

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Ribe 2011-01-05 14:37:18 Re: UUID column as pimrary key?
Previous Message Radosław Smogura 2011-01-05 14:28:40 Re: UUID column as pimrary key?