table with sort_key without gaps - Mailing list pgsql-general

From Janning Vygen
Subject table with sort_key without gaps
Date
Msg-id 200412091832.19728.vygen@gmx.de
Whole thread Raw
Responses Re: table with sort_key without gaps
List pgsql-general
Hi,

i have a table like this:

create table array (
  account text NOT NULL,
  id      int4 NOT NULL,
  value   text NOT NULL,
  PRIMARY KEY (account, id)
);

values like this:

acc1,1,'hi'
acc1,2,'ho'
acc1,3,'ha'
acc2,1,'ho'
acc3,1,'he'
acc3,2,'hu'

"id" should be positive
"id" should not have gaps within the same account
"id" should start counting by 1 for each account

i cant use sequences because they are producing gaps and doesn't start
counting by 1 for each account and i dont want to use postgresql array type
for various reasons.

for this model to function you need a lot of sophisticated plpgsql function to
insert, move or delete entries to keep

- did anyone implemented a table like this and wrote some custom
functions/triggers for inserting, deleting, moving and so on? If yes it would
be nice if he/she is willing to sahre the code with me.

- did anyone implemented a table like this and came to the conclusion that
this shouldn't be done for any reasons out of my sight? (i don't bother about
updating a primary key)

kind regards,
janning





pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Test
Next
From: "Najib Abi Fadel"
Date:
Subject: Re: postgresql and javascript