From: Jesus Sandoval <meli@mzt.megared.net.mx>
Cc: pgsql-admin@postgresql.org
Subject: Secuence not updated
Date: Sun, 18 Nov 2001 11:54:57 -0700
Message-ID: <3BF80401.59829735@mzt.megared.net.mx> (raw)
References: <9t3fpr$2o5a$1@news.tht.net>
<9386.1005940291@sss.pgh.pa.us>
Hello, I a small database (about 80 new records daily), I'm running postgresql
7.1.2 running in a RedHat Box 7.1, and the primary key is updated by an
automatic secuence, my application is in C languaje and I use the following
instruction to insert each row res = PQexec(conn, data) and the value of data
is "INSERT INTO captura (registro) VALUES ( 'expected data......') ", each
record has 4 columns: (the primary key is consecutivo)
Attribute | Type
| Modifier
---------+-------------------+--------------------------------------------
consecutivo | integer | not null default
nextval('"captura_consecutivo_seq"'::text)
fechahora | timestamp with time zone | not null default now()
registro | character varying(150) |
procesado | character(1) | not null default 'N'
everything worked perfectly by about 6 weeks but one day my application didn't
work because 'duplicate key in unique index´ I checked the problem and it was
because the value of consecutivo in the last record was 3 numbres higher than
the actual value of captura_consecutivo_seq.
maybe the problem was becase somebody reset the computer without doing a
shutdown.
I wan't some help in the following questions:
1) How was this possible do I need to make a commit after each INSERT?? or a
transaction is needed to update at the same time the record and the
secuence???
2) I want to make sure this simple integrity of data is kept always, is there
some way to guarantee this???? (I'm thinking in other applications with
Postgresql)
3) Maybe the simple solution in this case is to get rid of the primary key and
keeping the consecutivo column as a not unique field, (I need the field for
sorting purposes) is these OK??? (I mean normally in databases a primary key
is some kind of recommended, I was thinking that the secuence was the perfect
primary key but now I'm not sure).
Thanks in advace to your helping.
Jesus Sandoval
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-admin@postgresql.org
Cc: meli@mzt.megared.net.mx
Subject: Re: Secuence not updated
In-Reply-To: <3BF80401.59829735@mzt.megared.net.mx>
References: <9t3fpr$2o5a$1@news.tht.net> <9386.1005940291@sss.pgh.pa.us> <3BF80401.59829735@mzt.megared.net.mx>
* 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