Skip site navigation (1) Skip section navigation (2)

Re: Insert Question

From: <operationsengineer1(at)yahoo(dot)com>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Insert Question
Date: 2006-11-02 23:37:30
Message-ID: 20061102233730.65667.qmail@web33301.mail.mud.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
> > create sequence tmp_seq start with 42000005;
> > 
> > update products set document_number =
> > nextval('tmp_seq')
> > where ocument_number is null;
> > 
> > i had to do it this way because i actually had a
> few
> > entries in the db already.  it did work just fine,
> > though.
> 
> In this case you could:
> 
> create sequence temp_seq start with (select
> max(document_number) from products);
> 
> 
> > 
> > i learned to use...
> > 
> > drop sequence tmp_seq;
> > 
> > in order to reuse the sequence as i was playing
> around
> > with functionality.  otherwise, it would return an
> > error b/c the sequence already existed.
> 
> if you want to use the same sequence over again you
> could:
> 
> select set_val('temp_seq', select
> max(document_number) from products));
> and then do your update.
> 
> you will not need to drop your sequence this way.

Richard, good stuff.  thanks!


 
__________________________________________________________________________________________
Check out the New Yahoo! Mail - Fire up a more powerful email and get things done faster. 
(http://advision.webevents.yahoo.com/mailbeta) 


In response to

pgsql-novice by date

Next:From: ketemaDate: 2006-11-04 15:24:02
Subject: Select permissions on system tables
Previous:From: Richard Broersma JrDate: 2006-11-02 21:46:13
Subject: Re: Insert Question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group