pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marc Howard Zuckman <marc@fallon.classyad.com>
To: Thomas Good <tomg@admin.nrnet.org>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] abusing an aggregate funct
Date: Sat, 14 Nov 1998 10:01:41 -0500 (EST)
Message-ID: <Pine.LNX.4.02A.9811140953190.6343-100000@fallon.classyad.com> (raw)
In-Reply-To: <Pine.LNX.3.96.981114065037.6759A-100000@admin.nrnet.org>

On Sat, 14 Nov 1998, Thomas Good wrote:

> Due to the sheer girth of the table the following query, called from
> a data entry script,  takes a bit of time to finish:
> 
> SELECT max(rec_num) FROM crtrd1;
> 
> I use this to setup `rec_num + 1' for my query number (p_key)...any
> way I can speed this up a bit?  I've run vacuum analyze but the
> table size is doing me in...
> 
Use a sequence to generate rec_num.  See man create_sequence.

You can then use curval('sequence_name') to get the last
sequence number generated, or if you are performing an insert:
  insert into crtrd1 (p_key,otherdata) values (nextval('sequence_name',moredata);

You could also create the table using nextval as the default
value of p_key.  You may wish to create a unique_index on
p_key, but nextval is guaranteed not to generate duplicates
unless you allow it to rollover.





Marc Zuckman
marc@fallon.classyad.com

_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
_     Visit The Home and Condo MarketPlace		      _
_          http://www.ClassyAd.com			      _
_							      _
_  FREE basic property listings/advertisements and searches.  _
_							      _
_  Try our premium, yet inexpensive services for a real	      _
_   selling or buying edge!				      _
_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_




view thread (7+ messages)  latest in thread

Message-ID: <Pine.LNX.4.02A.9811140953190.6343-100000@fallon.classyad.com>
Permalink:  ../Pine.LNX.4.02A.9811140953190.6343-100000@fallon.classyad.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.02A.9811140953190.6343-100000@fallon.classyad.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: marc@fallon.classyad.com, tomg@admin.nrnet.org
  Subject: Re: [SQL] abusing an aggregate funct
  In-Reply-To: <Pine.LNX.4.02A.9811140953190.6343-100000@fallon.classyad.com>
  References: <Pine.LNX.3.96.981114065037.6759A-100000@admin.nrnet.org> <Pine.LNX.4.02A.9811140953190.6343-100000@fallon.classyad.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