pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedInserting and incrementing with MAX aggregate
3+ messages / 2 participants
[nested] [flat]
* Inserting and incrementing with MAX aggregate
@ 2001-01-23 20:01 Keith Perry <keith@vcsn.com>
2001-01-24 04:00 ` Re: Inserting and incrementing with MAX aggregate Ian Harding <iharding@pakrat.com>
0 siblings, 1 reply; 3+ messages in thread
From: Keith Perry @ 2001-01-23 20:01 UTC (permalink / raw)
To: pgsql-general@postgresql.org.pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Inserting and incrementing with MAX aggregate
2001-01-23 20:01 Inserting and incrementing with MAX aggregate Keith Perry <keith@vcsn.com>
@ 2001-01-24 04:00 ` Ian Harding <iharding@pakrat.com>
2001-01-24 16:11 ` Re: Inserting and incrementing with MAX aggregate Keith Perry <keith@vcsn.com>
0 siblings, 1 reply; 3+ messages in thread
From: Ian Harding @ 2001-01-24 04:00 UTC (permalink / raw)
To: pgsql-general@postgresql.org.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@vcsn.com
> http://vcsn.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Inserting and incrementing with MAX aggregate
2001-01-23 20:01 Inserting and incrementing with MAX aggregate Keith Perry <keith@vcsn.com>
2001-01-24 04:00 ` Re: Inserting and incrementing with MAX aggregate Ian Harding <iharding@pakrat.com>
@ 2001-01-24 16:11 ` Keith Perry <keith@vcsn.com>
0 siblings, 0 replies; 3+ messages in thread
From: Keith Perry @ 2001-01-24 16:11 UTC (permalink / raw)
To: pgsql-general@postgresql.org.pgsql-sql
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-01-24 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-01-23 20:01 Inserting and incrementing with MAX aggregate Keith Perry <keith@vcsn.com>
2001-01-24 04:00 ` Ian Harding <iharding@pakrat.com>
2001-01-24 16:11 ` Keith Perry <keith@vcsn.com>
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