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: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<body bgcolor="#ffffff" text="#000066">
<font size="-1"><font face="Helvetica, Arial, sans-serif">Nacef,<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>
Never rely on the internal implementation of a database to keep the
data in the order you insert/update.<br>
Nacef LABIDI wrote:
 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>
I will explain more my case :<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>
When I have tested this with SQLServer it works well, since the rows
doesn't change position on the DB.<br>
I hope that you understand my issue and I will provide any explanations
if someting isn't clear enough.<br>
Thanks to all<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
&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>
why do you think it stays in the same place in db?<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>
    <font color="#888888"><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=""
 target="_blank"></a> - blog dla ciebie (i moje
<pre class="moz-signature" cols="72">-- 
PGP Id 9EED2E09</pre>

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-2017 The PostgreSQL Global Development Group