pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ian Harding <iharding@pakrat.com>
To: pgsql-general@postgresql.org.pgsql-sql
Subject: Re: Inserting and incrementing with MAX aggregate
Date: Tue, 23 Jan 2001 20:00:51 -0800
Message-ID: <3A6E5373.BDF7674B@pakrat.com> (raw)
References: <3A6DE314.A85DEEB0@vcsn.com>

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




view thread (3+ messages)  latest in thread

Message-ID: <3A6E5373.BDF7674B@pakrat.com>
Permalink:  ../3A6E5373.BDF7674B@pakrat.com/
Also on:    postgresql.org/message-id/3A6E5373.BDF7674B@pakrat.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: iharding@pakrat.com, pgsql-general@postgresql.org.pgsql-sql
  Subject: Re: Inserting and incrementing with MAX aggregate
  In-Reply-To: <3A6E5373.BDF7674B@pakrat.com>
  References: <3A6DE314.A85DEEB0@vcsn.com> <3A6E5373.BDF7674B@pakrat.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox