Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Interfaces Jdbc > Re: Creating a ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 1935 of 2010
Post > Topic >>

Re: Creating a sequence

by craig@[EMAIL PROTECTED] (Craig Ringer) Apr 24, 2008 at 01:00 AM

Chris wrote:
> That was my problem, I didn't know where or how to create the sequence. 
> Got it to work now. :D
> So, should the standard practice be to create a sequence for every
table? 

That leads in to the synthetic vs natural primary key debate, which
isn't worth getting into here.

If you have a synthetic key on a table (a "meaningless" integer
identifier generated by the application or database) then a sequence is
an extremely good way of generating such identifiers. The use of a
sequence permits multiple concurrent inserts without risk of conflict
and without the need for locking.

You *WILL* get gaps in your primary key values, though, where
transactions have rolled back. Your application should be designed not
to care about this.

By the way, I pointed out the stupid way of setting a sequence start
value. What I should've written was:

CREATE SEQUENCE employee_emp_uid_seq;
SELECT setval('employee_emp_uid_seq',
    (SELECT max(emp_uid) FROM employee));

--
Craig Ringer

-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
 




 4 Posts in Topic:
Creating a sequence
cmattmiller@[EMAIL PROTEC  2008-04-23 08:46:10 
Re: Creating a sequence
craig@[EMAIL PROTECTED]   2008-04-23 23:00:44 
Re: Creating a sequence
craig@[EMAIL PROTECTED]   2008-04-23 23:04:22 
Re: Creating a sequence
craig@[EMAIL PROTECTED]   2008-04-24 01:00:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Aug 20 8:41:43 CDT 2008.