Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 134BC476538 for ; Thu, 30 May 2002 19:36:16 -0400 (EDT) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 30269475F94 for ; Thu, 30 May 2002 19:34:48 -0400 (EDT) Received: from [66.219.92.2] (HELO chocolate-mousse) by davinci.ethosmedia.com (CommuniGate Pro SMTP 3.5.9) with ESMTP id 1494884; Thu, 30 May 2002 16:34:49 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: David Busby , 'Postgres-PHP' Subject: Re: UUID/GUID information Date: Thu, 30 May 2002 16:34:52 -0700 X-Mailer: KMail [version 1.4] References: <35363AB30BF2D311B73C0050DAB989F063C3@SEAPDC01> In-Reply-To: <35363AB30BF2D311B73C0050DAB989F063C3@SEAPDC01> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200205301634.52634.josh@agliodbs.com> X-Archive-Number: 200205/118 X-Sequence-Number: 1250 David, > Perhaps I should have mentioned that I'm building a multi-database soluti= on > (20+ databases) in which all 20+ DBs must use the same identifier across > databases for some objects (ex: Automobile Brands) but their own identifi= er > for their own data (ex: Accouts/Clients) this way when the child database > publish to the master there is no possiblity of some object having the sa= me > identifer as another...and the object identifier can stay the same across > all 20+ DBs.=20=20 >=20 > The GUID from Micro$oft is formatted like > {01234567-89AB-CDEF-0123-456789ABCDEF} it represents a 16 byte number that > is again unique in spacetime. Is there PostgreSQL solution for something > like that or will I have to come up with my own. In that case, you should have the budget for some programming, yes? The answer is quite simple: 1. You set up a universal sequence as I described. 2. You give each server its own 4-byte Server ID, and put it in the table server_id. Use whatever number you want; I might suggest something based on the IP address of the machine (though unfortunately IP=20 addresses are 4 bytes unsigned, so you can't use them directly). 3. You create a function as follows: CREATE FUNCTION unique_id () RETURNS INT8 AS ' SELECT ((server_id.server_id::INT8 * (2^31 - 1)::INT8) +=20 NEXTVAL('universal_sq')) FROM server_id; ' LANGUAGE 'sql'; (Somebody correct my math if I'm off, here) Alternately, you could use a random 4-byte number instead of the server_id,= =20 which wouldn't be perfect but would give you only about a 20 in 2.4 billion= =20 chance of a conflict. --=20 -Josh Berkus --=20 -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco