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 f0R19Xq71212 for ; Fri, 26 Jan 2001 20:09:33 -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 f0OGTZq28266; Wed, 24 Jan 2001 11:29:35 -0500 (EST) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f0OGIKx82229; Wed, 24 Jan 2001 11:18:21 -0500 (EST) (envelope-from news) From: Keith Perry X-Newsgroups: comp.databases.postgresql.general,comp.databases.postgresql.sql Subject: Re: Inserting and incrementing with MAX aggregate Date: Wed, 24 Jan 2001 11:11:34 -0500 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 37 Message-ID: <3A6EFEB6.3A0C95C@vcsn.com> References: <3A6DE314.A85DEEB0@vcsn.com> <3A6E5373.BDF7674B@pakrat.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.76 [en] (Win95; U) X-Accept-Language: en To: pgsql-general@postgresql.org.pgsql-sql@postgresql.org X-Archive-Number: 200101/1318 X-Sequence-Number: 3614 Ahhh, thank you that worked. I don't know why but for some reason I didn't think I could do a subquery in an insert *laff*- 'learn something new everyday :) Keith- Ian Harding wrote: > 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