Skip site navigation (1) Skip section navigation (2)

Re: After updating dataset the record goes to the end of the dataset

From: Padam J Singh <padam(dot)singh(at)inventum(dot)cc>
To: Nacef LABIDI <nacef(dot)l(at)gmail(dot)com>
Cc: depesz(at)depesz(dot)com, Roland Voegtli <voegtli(at)scnat(dot)ch>, pgsql-sql(at)postgresql(dot)org
Subject: Re: After updating dataset the record goes to the end of the dataset
Date: 2008-04-22 11:02:57
Message-ID: 480DC5E1.5060508@inventum.cc (view raw or flat)
Thread:
Lists: pgsql-sql
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000066">
<font size="-1"><font face="Helvetica, Arial, sans-serif">Nacef,<br>
<br>
Simply add a SERIAL column to your table. When you add a new row, a new
value will be stored in this column if you do not specify the column
name in the insert query.<br>
In your select query, always order by this column.<br>
When doing an update , do not update this column. When re-ordering,
update this column to indicate order. So if you want to move a row up,
issue two update queries, updating this column. Make sure you have some
primary key in this table to uniquely identify these row.<br>
<br>
Never rely on the internal implementation of a database to keep the
data in the order you insert/update.<br>
<br>
Padam<br>
</font></font><br>
Nacef LABIDI wrote:
<blockquote
 cite="mid:f16f7ea00804220331u226df1ean9a17e12d9324e078(at)mail(dot)gmail(dot)com"
 type="cite">You are right about the fact that the rows don't keep the
order they where created with at the start. I have verfied this.<br>
  <br>
I will explain more my case :<br>
  <br>
I am writing an application where here is some resources to plan events
on. I want to provide the user with the ability to customize the order
in which resources are displayed on the screen. So there is a mapping
between the rows positions in the dataset and they display positions.
After updating one of these resources the row jumps to the end of the
dataset so does the resource on the display. And the order gets
scrambled. I cannot set this order in the databe since it is
customizable for each user.<br>
  <br>
When I have tested this with SQLServer it works well, since the rows
doesn't change position on the DB.<br>
  <br>
I hope that you understand my issue and I will provide any explanations
if someting isn't clear enough.<br>
  <br>
Thanks to all<br>
Nacef<br>
  <br>
  <div class="gmail_quote">On Tue, Apr 22, 2008 at 12:15 PM, hubert
depesz lubaczewski &lt;<a moz-do-not-send="true"
 href="mailto:depesz(at)depesz(dot)com">depesz(at)depesz(dot)com</a>&gt; wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
    <div class="Ih2E3d">On Tue, Apr 22, 2008 at 12:10:41PM +0200, Nacef
LABIDI wrote:<br>
&gt; Yes I don't issue any sort statement, and I indeed want the data
to be show<br>
&gt; as it is stored in the database. But after updating a row (I don't
update<br>
&gt; the ID, just some fields), it keeps its same place on the DB but
jumps to<br>
&gt; the end of the dataset and by the way to the end of the DBGrid.<br>
    <br>
    </div>
why do you think it stays in the same place in db?<br>
    <br>
besides - without "order by" you cannot depend on the order of rows.<br>
basically i treat them as in "random" order (which is not true, but<br>
helps me remember to never count on the "default" ordering.<br>
    <br>
depesz<br>
    <font color="#888888"><br>
--<br>
quicksil1er: "postgres is excellent, but like any DB it requires a<br>
highly paid DBA. &nbsp;here's my CV!" :)<br>
    <a moz-do-not-send="true" href="http://www.depesz.com/"
 target="_blank">http://www.depesz.com/</a> - blog dla ciebie (i moje
CV)<br>
    </font></blockquote>
  </div>
  <br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
PGP Id 9EED2E09</pre>
</body>
</html>


Attachment: unknown_filename
Description: text/html (3.4 KB)

In response to

pgsql-sql by date

Next:From: Craig RingerDate: 2008-04-22 12:30:28
Subject: Re: Problems with function while migrating from Windows to Linux
Previous:From: hubert depesz lubaczewskiDate: 2008-04-22 11:02:14
Subject: Re: After updating dataset the record goes to the end of the dataset

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group