I am new to Postgresql and I am using version 9.3. I have a table in which i have a couple of rows. My question is, when I update a row, the row number is changed and it is moved to the the last location in the table. My question is: is this the default behavior, because I think when a row is updated, it should not be moved from its place? The operation seems to be like deleting and then inserting the row again.
Here is the sample SQL:
CREATE TABLE cities
(
city_id serial,
city_name character varying(50),
PRIMARY KEY (city_id)
);
INSERT INTO cities (city_name) VALUES ('ABC');
INSERT INTO cities (city_name) VALUES ('DEF');
INSERT INTO cities (city_name) VALUES ('GHI');
INSERT INTO cities (city_name) VALUES ('JKL');
UPDATE cities
SET city_name = 'XYZ'
WHERE city_id = 1;
Now, on:
SELECT * FROM cities;
moves the updated row with id 1 at the last location.
2, DEF
3, GHI
4, JKL
1, XYZ
Thanks