Обсуждение: Error inserting row on unique key

Поиск
Список
Период
Сортировка

Error inserting row on unique key

От
"Benjamin Krajmalnik"
Дата:
I have a large table which uses a sequence for column which is defined as the primary key.
Our systems is a real time data acquisition system, so we have "insert" statements going through it wrapped inside
storedprocedure. 

Every once in a while I get an inserio error on a violation of a unique constraint on the primary key.
Could this be caused by a subsequent call to the stored procedure which took place before the sequence on the prior
storedprocedure fired? 
If so, do you recommend taking the call to the sequence out of the columns constraint definition and manually calling
itas the firs step in the SP call? 

As I said, this does not happen very often, but I have seen it happen.

Regards,

Benjamin

Re: Error inserting row on unique key

От
Tom Lane
Дата:
"Benjamin Krajmalnik" <kraj@illumen.com> writes:
> I have a large table which uses a sequence for column which is defined as the primary key.
> Our systems is a real time data acquisition system, so we have "insert" statements going through it wrapped inside
storedprocedure. 

> Every once in a while I get an inserio error on a violation of a unique constraint on the primary key.

Let's see that stored procedure ...

            regards, tom lane

Re: Error inserting row on unique key

От
Allan Kamau
Дата:
Benjamin,
Are you sure the sequence is the only source of the
values of the primary key field of all records in this
table, that no records may have been inserted using
primary key field values generated from sources other
than the sequence.

Allan.

--- Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "Benjamin Krajmalnik" <kraj@illumen.com> writes:
> > I have a large table which uses a sequence for
> column which is defined as the primary key.
> > Our systems is a real time data acquisition
> system, so we have "insert" statements going through
> it wrapped inside stored procedure.
>
> > Every once in a while I get an inserio error on a
> violation of a unique constraint on the primary key.
>
> Let's see that stored procedure ...
>
>             regards, tom lane
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please
> send an appropriate
>        subscribe-nomail command to
> majordomo@postgresql.org so that your
>        message can get through to the mailing list
> cleanly
>

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

Re: Error inserting row on unique key

От
"Benjamin Krajmalnik"
Дата:
The sequence is the only source.
The good news is that I was using the sequence to enable purging of old data to maintain our retention period.
I am going to try a different methodology by using table partitioning - one inherited table for each month of data.
Thatway after the retention period is done I can jusr truncate the table without affecting performance in balancing the
indices(at least I hope that's what will happen :). 

Each row being inserted has a test time (timestamp).  I plan to use extract(month from timestampfield) to tag it for a
specificpartition. 
I am still trying to figure out this thing out.  Would it be best to use a before insert trigger on the parent table,
ora rule? 
The pseudocode would be such as:

case partitionid
of 1
    insert data into partition1
of 2
    insert data into partition1
.
.
of 12
    insert data ito partition 12
end case

Any suggestions on how to formulate either the trigger procedure or a rule would be greatly appreciated.

Regards,

Benjamin
-----Original Message-----
From: Allan Kamau [mailto:kamauallan@yahoo.com]
Sent: Thursday, April 20, 2006 3:38 PM
To: Benjamin Krajmalnik
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] Error inserting row on unique key


Benjamin,
Are you sure the sequence is the only source of the
values of the primary key field of all records in this
table, that no records may have been inserted using
primary key field values generated from sources other
than the sequence.

Allan.

--- Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "Benjamin Krajmalnik" <kraj@illumen.com> writes:
> > I have a large table which uses a sequence for
> column which is defined as the primary key.
> > Our systems is a real time data acquisition
> system, so we have "insert" statements going through
> it wrapped inside stored procedure.
>
> > Every once in a while I get an inserio error on a
> violation of a unique constraint on the primary key.
>
> Let's see that stored procedure ...
>
>             regards, tom lane
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please
> send an appropriate
>        subscribe-nomail command to
> majordomo@postgresql.org so that your
>        message can get through to the mailing list
> cleanly
>

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com