Re: [SQL] Create on insert a unique random number

2008-03-19 Thread D'Arcy J.M. Cain
On Wed, 19 Mar 2008 08:28:28 -0700 Steve Midgley <[EMAIL PROTECTED]> wrote: > I'm not following this line. Maybe we're talking about two different > things here.. I don't know if Lance is using "CRUD" methodology per se, > but that's a well accepted web approach and uses (generally) serial > pri

Re: [SQL] Create on insert a unique random number

2008-03-19 Thread Steve Midgley
At 06:47 AM 3/19/2008, D'Arcy J.M. Cain wrote: But your suggestion was to base this key on the serial primary key so where is your index collision protection? You are going to get collisions on both the serial key and, to a lesser extent, your generated one. Besides, has anyone ever demonstrated

Re: [SQL] Create on insert a unique random number

2008-03-19 Thread D'Arcy J.M. Cain
On Tue, 18 Mar 2008 13:57:39 -0700 Steve Midgley <[EMAIL PROTECTED]> wrote: > At 12:36 PM 3/18/2008, D'Arcy J.M. Cain wrote: > >On Tue, 18 Mar 2008 12:23:35 -0700 > >Steve Midgley <[EMAIL PROTECTED]> wrote: > > > 1) Create a second field (as someone recommend on this list) that > > is an > > > MD5

Re: [SQL] Create on insert a unique random number

2008-03-19 Thread hubert depesz lubaczewski
On Tue, Mar 18, 2008 at 01:40:42PM -0500, Campbell, Lance wrote: > This is not a security approach. It is more about not giving obvious > access to people that want to mess around. 1. keep primary key using standard serial. it will make your life a bit simpler. 2. add column for text random ident

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Steve Midgley
At 12:36 PM 3/18/2008, D'Arcy J.M. Cain wrote: On Tue, 18 Mar 2008 12:23:35 -0700 Steve Midgley <[EMAIL PROTECTED]> wrote: > 1) Create a second field (as someone recommend on this list) that is an > MD5 of your primary key. Use that as your "accessor" index from the web I strongly disagree fo

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread D'Arcy J.M. Cain
On Tue, 18 Mar 2008 12:23:35 -0700 Steve Midgley <[EMAIL PROTECTED]> wrote: > 1) Create a second field (as someone recommend on this list) that is an > MD5 of your primary key. Use that as your "accessor" index from the web I strongly disagree for three reasons. First, if you are going to gener

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread D'Arcy J.M. Cain
On Tue, 18 Mar 2008 13:40:42 -0500 "Campbell, Lance" <[EMAIL PROTECTED]> wrote: > Why use a random number as a primary key? Security via obscurity. Something with very short shelf life but... > I build web applications for a living. In most of my applications it is > preferable to use a random

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Steve Midgley
At 11:58 AM 3/18/2008, [EMAIL PROTECTED] wrote: Date: Tue, 18 Mar 2008 13:40:42 -0500 From: "Campbell, Lance" <[EMAIL PROTECTED]> To: "Vivek Khera" <[EMAIL PROTECTED]>, Subject: Re: Create on insert a unique random number Message-ID: <[EMAIL PROTECTED]> Thanks for all of your input.

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Vivek Khera
On Mar 18, 2008, at 2:40 PM, Campbell, Lance wrote: Why use a random number as a primary key? Security via obscurity. I build web applications for a living. In most of my applications it is preferable to use a random primary key. Why? Don't expose the actual ID to the end user; only ex

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Erik Jones
On Mar 18, 2008, at 1:40 PM, Campbell, Lance wrote: Thanks for all of your input. It appears that the best way to do this is to create a default random number in the primary id field in the table definition and then return that value after insert. If an exception occurs because of duplicates

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Campbell, Lance
lto:[EMAIL PROTECTED] On Behalf Of Vivek Khera Sent: Tuesday, March 18, 2008 12:57 PM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Create on insert a unique random number On Mar 18, 2008, at 1:03 PM, Campbell, Lance wrote: > The field n is not random but is sequential. Is there something I > s

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Vivek Khera
On Mar 18, 2008, at 1:03 PM, Campbell, Lance wrote: The field n is not random but is sequential. Is there something I should do to make the serial number random? Depending on your "randomness" need, you can alter the increment of the sequence so it changes by a different amount than "1" on

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread A. Kretschmer
am Tue, dem 18.03.2008, um 12:03:31 -0500 mailte Campbell, Lance folgendes: > I created the following table: > > create table xyz ( > n serial, > abc character varying, > constraint n_pkey primary key (n)); > > Each time I do an insert: > > insert into xyz(abc) values('adf6'); > > The field

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread D'Arcy J.M. Cain
On Tue, 18 Mar 2008 17:51:39 +0100 "A. Kretschmer" <[EMAIL PROTECTED]> wrote: > am Tue, dem 18.03.2008, um 9:43:01 -0700 mailte chester c young folgendes: > > > When inserting a record is there a way to have postgres create a > > > random number for a field such that it is unique? > > > > you co

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread paul rivers
Campbell, Lance wrote: I created the following table: create table xyz ( n serial, abc character varying, constraint n_pkey primary key (n)); Each time I do an insert: insert into xyz(abc) values('adf6'); The field n is not random but is sequential. Is there something I should do to make

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread Campbell, Lance
2008 11:52 AM To: pgsql-sql@postgresql.org Subject: Re: [SQL] Create on insert a unique random number am Tue, dem 18.03.2008, um 9:43:01 -0700 mailte chester c young folgendes: > > > When inserting a record is there a way to have postgres create a > > random number for a fie

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread A. Kretschmer
am Tue, dem 18.03.2008, um 9:43:01 -0700 mailte chester c young folgendes: > > > When inserting a record is there a way to have postgres create a > > random number for a field such that it is unique? > > > you could use oid No! No oid, it's deprecated. The solution: use serial. Andreas --

Re: [SQL] Create on insert a unique random number

2008-03-18 Thread chester c young
> When inserting a record is there a way to have postgres create a > random number for a field such that it is unique? you could use oid Looking for last minute shopping deals? Find them fast with Ya

[SQL] Create on insert a unique random number

2008-03-18 Thread Campbell, Lance
When inserting a record is there a way to have postgres create a random number for a field such that it is unique? Thanks, Lance Campbell Project Manager/Software Architect Web Services at Public Affairs University of Illinois 217.333.0382 http://webservices.uiuc.edu