Re: Inserting and incrementing with MAX aggregate

From: Ian Harding <iharding(at)pakrat(dot)com>
To: pgsql-general(at)postgresql(dot)org(dot)pgsql-sql(at)postgresql(dot)org
Subject: Re: Inserting and incrementing with MAX aggregate
Date: 2001-01-24 04:00:51
Message-ID: 3A6E5373.BDF7674B@pakrat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

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(at)vcsn(dot)com
> http://vcsn.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Wall 2001-01-24 04:30:10 MySQL has transactions
Previous Message Dave Cramer 2001-01-24 03:35:11 Re: VACUUM ANALYZE FAILS on 7.0.3

Browse pgsql-sql by date

  From Date Subject
Next Message Forest Wilkinson 2001-01-24 04:35:27 Re: unreferenced primary keys: garbage collection
Previous Message Michael Davis 2001-01-24 02:55:45 RE: retrieving user's groups