From: | Rob Brown-Bayliss <rob(at)zoism(dot)org> |
---|---|
To: | PostgreSQL General List <pgsql-general(at)postgresql(dot)org> |
Subject: | problem wit hsequence as primary key |
Date: | 2002-07-26 04:33:38 |
Message-ID: | 1027658012.5551.11.camel@everglade.zoism.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi, I was insertingrows into a table and had this error:
Cannot insert a duplicate key into unique index stock_transactions_pkey
Now the primary key is inserted by this function:
CREATE FUNCTION "set_primary_key" () RETURNS text AS '
DECLARE
sequence_number text;
location_number text;
retval text;
BEGIN
location_number := to_char(get_loc_key(),''999MI'');
location_number := trim(both '' '' from location_number);
sequence_number := to_char(nextval(''location_seq''),''99999MI'');
sequence_number := trim(both '' '' from sequence_number);
retval := location_number || ''-'' || sequence_number;
RETURN retval;
END;
' LANGUAGE 'plpgsql';
which results in valuse like 12-1234 as a text primary key.
The location_seq is up to 100005 at the moment so how am I getting
duplicate primary keys?
--
*
* Rob Brown-Bayliss
*
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2002-07-26 05:00:24 | Re: regression test |
Previous Message | Mark Taylor | 2002-07-26 02:38:35 | Re: Postgres user |