problem wit hsequence as primary key - Mailing list pgsql-general

From Rob Brown-Bayliss
Subject problem wit hsequence as primary key
Date
Msg-id 1027658012.5551.11.camel@everglade.zoism.org
Whole thread Raw
Responses Re: problem wit hsequence as primary key
List 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

*

pgsql-general by date:

Previous
From: Darren Ferguson
Date:
Subject: Re: Postgres user
Next
From: Bruce Momjian
Date:
Subject: Re: regression test