Received: from www-uk-05.digiserve.com ([195.97.231.11]) by mail.postgresql.org (8.11.3/8.11.1) with ESMTP id f2K74RN63332 for ; Tue, 20 Mar 2001 02:04:28 -0500 (EST) (envelope-from dev@archonet.com) Received: from mainbox.archonet.com (mwynhau.demon.co.uk [193.237.186.96]) by www-uk-05.digiserve.com (8.9.1/8.9.1) with ESMTP id HAA01780; Tue, 20 Mar 2001 07:05:16 GMT Received: from archonet.com (ibook.archonet.com [192.168.1.32]) by mainbox.archonet.com (Postfix) with ESMTP id 5F3832A688; Mon, 19 Mar 2001 23:12:10 +0000 (GMT) Message-ID: <3AB6922E.89E78E4B@archonet.com> Date: Mon, 19 Mar 2001 23:11:43 +0000 From: Richard Huxton X-Mailer: Mozilla 4.7C-CCK-MCD {C-UDP; EBM-APPLE} (Macintosh; I; PPC) X-Accept-Language: en MIME-Version: 1.0 To: postgresql Cc: PgSQL-SQL Subject: Re: serial type question References: <200103191733.f2JHXdN01064@mail.postgresql.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200103/385 X-Sequence-Number: 2053 postgresql wrote: > > I have a table that I want to add a serial type column. Is there a way > to add it or do I have to create a new table and insert into it. I have > experimented with: > > insert into newdb (name) select name from olddb order by jobno; > > however, pg does not allow the 'order by' during an insert/select Doesn't make sense on an insert - you want an alter table followed by an update. An insert will add new rows, not just add values to a column. > I am on version 7.0.3 > > Maybe I don't need to do this. What I am trying to accomplish is to > have PG create job numbers. Today, I only have 2 workstations that > push jobs into the server and PG tracks the job number. However, I > have been informed that in the next 6-8 months the number of job > creation workstations will grow to 8 - 10. A serial type is basically nothing more than a sequence with a column that uses the sequence as a default value. There's more on this in the docs (a couple of lines in the notes I wrote off techdocs.postgresql.org) but the simplest way to see how it works is to define a table foo with a serial in it and do a \d or pg_dump it to see how it works. > I would like to migrate to a job number created when the insert is > done. Once you see how it works, pg_dump the database, edit the file and re-import the data. Nice clean solution and easy to cope with if something goes wrong. - Richard Huxton