Unix Technical Forum

Re: Delete after trigger fixing the key of row numbers

This is a discussion on Re: Delete after trigger fixing the key of row numbers within the Pgsql General forums, part of the PostgreSQL category; --> On 2008-03-28 13:27, Teemu Juntunen wrote: > I am developing an ERP to customer and I have made few ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:23 AM
Tomasz Ostrowski
 
Posts: n/a
Default Re: Delete after trigger fixing the key of row numbers

On 2008-03-28 13:27, Teemu Juntunen wrote:

> I am developing an ERP to customer and I have made few tables using a
> row number as part of the key. When deleting a line from such a
> table, I have made an after delete trigger, which fixes the row
> numbers with following command:
> UPDATE orderrow SET row = row - 1 WHERE order = old.order AND row > old.row;


Whoa! That was a very bad design decision. This will eat your data
sooner or later.

> It seems like it tries to do the change in wrong order at the receipt table.


You can force an order of updates using a loop in plpgsql. But you
should redesign your database before it is too late.

Regards
Tometzky
--
....although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
Winnie the Pooh


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:23 AM
brian
 
Posts: n/a
Default Re: VS: Delete after trigger fixing the key of row numbers

Teemu Juntunen, e-ngine wrote:
> Hi Tomasz,
>
> with receipt rows I can't see any other option with key as running number.
> First I tried to use serial, but it didn't start from zero again when the
> foreign key (receipt number) changes. It just continues the serial despite
> of the foreign key.
>
> Then I decided to do my own serial which keeps it in order even when some
> rows are deleted from the middle. Of course I could just leave the row
> numbers as is, but there are some advantages at the program, if the serial
> is linear. What is the danger you see in this row number update trigger?
>


If you'd like to have a linear count of your result set it shouldn't be
difficult to implement that in your client-side application code (for
loop, for instance). You don't need to use the serial for display
purposes but it's very helpful for maintaining intact relations.

Besides, if this table has any associations with others, doing this
would seem to make your archived data next to useless if you ever need it.

b

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:52 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com