Re: Insert Question
| От | |
|---|---|
| Тема | Re: Insert Question | 
| Дата | |
| Msg-id | 20061102212046.15596.qmail@web33301.mail.mud.yahoo.com обсуждение исходный текст  | 
		
| Ответ на | Re: Insert Question (Richard Broersma Jr <rabroersma@yahoo.com>) | 
| Ответы | 
                	
            		Re: Insert Question
            		
            		 | 
		
| Список | pgsql-novice | 
> > hhi all,
> >
> > long time no askie question, but here goes...
> >
> > i want to insert sequential document numbers into
> a
> > products table
> >
> > my current setup is like so:
> >
> > product_number document_number
> > 1001
> > 1002
> > 1006
> > 1005
> >
> > i want an insert statement that will yield the
> > following:
> >
> > product_number document_number
> > 1001           42000001
> > 1002           42000002
> > 1006           42000003
> > 1005           42000004
> >
> > relative order means nothing, but i do want
> sequential
> > document numbers.
> >
> > how can i go about getting this done as
> efficiently as
> > possible?
> >
> > as always, tia.
>
> create sequence tmp_seq start with 42000000;
>
> update products set document_number =
> nextval('tmp_seq');
>
> Would this do what you want?
it led me in the right direction.
here is the code:
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.
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.
thanks again.
____________________________________________________________________________________
Access over 1 million songs - Yahoo! Music Unlimited
(http://music.yahoo.com/unlimited)
		
	В списке pgsql-novice по дате отправления: