Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f0OE7aq08270 for ; Wed, 24 Jan 2001 09:07:36 -0500 (EST) (envelope-from pgsql-general-owner@postgresql.org) Received: from news.tht.net (news.hub.org [216.126.91.242]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f0O3xZ031887; Tue, 23 Jan 2001 22:59:35 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f0O3sgs69631; Tue, 23 Jan 2001 22:54:42 -0500 (EST) (envelope-from news) From: Ian Harding X-Newsgroups: comp.databases.postgresql.general,comp.databases.postgresql.sql Subject: Re: Inserting and incrementing with MAX aggregate Date: Tue, 23 Jan 2001 20:00:51 -0800 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 29 Message-ID: <3A6E5373.BDF7674B@pakrat.com> References: <3A6DE314.A85DEEB0@vcsn.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: scrappy@hub.org X-Mailer: Mozilla 4.61 [en] (X11; U; Linux 2.2.12-20 i686) X-Accept-Language: en To: pgsql-general@postgresql.org.pgsql-sql@postgresql.org X-Archive-Number: 200101/1162 X-Sequence-Number: 3428 Could you not: insert into events (eid,name) values ((SELECT max(eid) FROM EVENTS)+1,'server down'); It looks like it would work. It's just a subquery... Ian Keith Perry wrote: > I was wondering if this statement was still supported in 7.0.x versions > of pgSQL. I upgraded from a 6.x version where say: > > insert into events (eid,name) values (max(eid)+1,'server down'); > > works but not in the 7.x variants. > > I know that I could use the serial type for that column but in the > interest not having to rewrite the code (or dump, drop and recreate the > tables/data), I wanted to know if there was a more stand way to > incrementing a field automatically that would be fairly portable. Any > help would be appreciated. > > Keith Perry > VCSN Inc. > keith@vcsn.com > http://vcsn.com