Re: question about auto increment like

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

Re: question about auto increment like

От:
Josh Berkus <josh@agliodbs.com>
Дата:
Don,

> I'm looking for a way to auto increment a field each time an new entry is 
> added (kind of like in mysql) 

See SERIAL data type.

> but  I also want it to automatically adjust all 
> other entries in case one of them is deleted if u see what I mean.

No, I don't.  Can you be more specific?


-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco

Re: question about auto increment like

От:
Josh Berkus <josh@agliodbs.com>
Дата:
Pat,

> say u have 3 entries, the first entry (let's call it A) value is "1" the 
second(let's call it B) is "2" and the third(let's call it C) is "3".
> If I delete B, I would like C value to become "2" ie to take B value.
> hope u see what I'm sayin.

What do these numbers represent?   If we're talking about a key for the table, 
that's such a bad idea I won't help you with it.   If we're talking about 
something else (like an entry sequence number) there are a few ways to do it, 
but an auto-increment number (e.g. SERIAL) isn't one of them.

-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco

Re: question about auto increment like

От:
Josh Berkus <josh@agliodbs.com>
Дата:
pat,

> >>What do these numbers represent?   If we're talking about
> >>a key for the table, 
> >>that's such a bad idea I won't help you with it.   If
> >>we're talking about 
> >>something else (like an entry sequence number) there are
> >>a few ways to do it, 
> >>but an auto-increment number (e.g. SERIAL) isn't one of
> >>them.
> 
> indeed it is a entry sequence number, not a key.

You will need a trigger to keep it sequential, then.   I have a set of 
triggers that does this for an ordered set of entries in a table. Keep in 
mind that this will make deletes from the table really slow, as all of the 
entries higher than the deleted row will have to be adjusted.

Unfortunately, I'm in the middle of a large data conversion right now; please 
pester me in a week and I'll get you the triggers.  Or maybe someone else 
will post something.


-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco

question about auto increment like

От:
Don Patou <pknoob@noos.fr>
Дата:
I'm looking for a way to auto increment a field each time an new entry is 
added (kind of like in mysql) but  I also want it to automatically adjust all 
other entries in case one of them is deleted if u see what I mean.
do I need to write a function myself or is there a functionnality in pgsql 
that does just that?

thanx in advance

Re: question about auto increment like

От:
"pat pat" <pknoob@noos.fr>
Дата:
[------  En réponse à  Josh Berkus :  ------]
 
>>Don,

>>See SERIAL data type.
>>
>>> but  I also want it to automatically adjust all 
>>> other entries in case one of them is deleted if u see
>>what I mean.
>>
>>No, I don't.  Can you be more specific?

say u have 3 entries, the first entry (let's call it A) value is "1" the second(let's call it B) is "2" and the third(let's call it C) is "3".
If I delete B, I would like C value to become "2" ie to take B value.
hope u see what I'm sayin.

thanx in advance

Re: question about auto increment like

От:
"pat pat" <pknoob@noos.fr>
Дата:

>>What do these numbers represent?   If we're talking about
>>a key for the table, 
>>that's such a bad idea I won't help you with it.   If
>>we're talking about 
>>something else (like an entry sequence number) there are
>>a few ways to do it, 
>>but an auto-increment number (e.g. SERIAL) isn't one of
>>them.

indeed it is a entry sequence number, not a key.

FAQ