Skip site navigation (1) Skip section navigation (2)

Re: [PERFORM] Very Urgent : Sequences Problem

From: tv(at)fuzzy(dot)cz
To: "Merlin Moncure" <mmoncure(at)gmail(dot)com>
Cc: Kranti&#65533(at)sq(dot)gransy(dot)com, "K K Parisa" <kranti(dot)parisa(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org, pgsql-performance(at)postgresql(dot)org
Subject: Re: [PERFORM] Very Urgent : Sequences Problem
Date: 2008-11-19 16:53:09
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-adminpgsql-performance
> On Wed, Nov 19, 2008 at 10:54 AM, Kranti&#65533; K K Parisa
> <kranti(dot)parisa(at)gmail(dot)com> wrote:
>> Hi,
>> I have defined sequence on a table something like this
>> CREATE SEQUENCE items_unqid_seq
>>   MAXVALUE 9223372036854775807
>>   START 7659
>>   CACHE 1;
>> this is on a table called items. where i have currently the max(unq_id)
>> as
>> 7659.
>> and in the stored procedure when i am inserting values into the items
>> table
>> for the unq_id column i am using the sequence as follows:
>> nextval('items_unqid_seq'::text)
>> it seems to be working some times. and the sequences are not getting
>> updated
>> sometime. which is casuing primary key exceptions.
>> please advise as soon as possible.
>> is there any trivial problem with sequences in postgresql??
> no (at least none that I know of).
> maybe if you posted the source of your procedure?  I bet your error is
> coming form some other source.

Are you sure you're using the nextval() properly whenever you insert data
into the table? This usually happens when a developer does not use it
properly, i.e. he just uses a (select max(id) + 1 from ...) something like
that. One of the more creative ways of breaking sequences was calling
nextval() only for the first insert, and then adding 1 to the ID.

BTW. do you have RULEs defined on the table? Some time ago I run into a
problem with RULEs defined on the table, as all the rules are evaluated -
I've used nextval() in all the rules so it was incremented for each rule
and it was not clear which value was actually used. So it was not sure
which value to use in a following insert (as a FK value).


In response to

pgsql-performance by date

Next:From: AndrusDate: 2008-11-19 20:29:00
Subject: Hash join on int takes 8..114 seconds
Previous:From: Merlin MoncureDate: 2008-11-19 16:40:52
Subject: Re: [PERFORM] Very Urgent : Sequences Problem

pgsql-admin by date

Next:From: Barbara StephensonDate: 2008-11-19 20:12:18
Subject: Re: open source ERD for postgresql database
Previous:From: Merlin MoncureDate: 2008-11-19 16:40:52
Subject: Re: [PERFORM] Very Urgent : Sequences Problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group