PostgreSQL - retrieving items in order they were stored

前端 未结 2 1993
悲哀的现实
悲哀的现实 2021-01-23 14:59

Folks, I have the following table:

CREATE TABLE IF NOT EXISTS users(
 userid           CHAR(100)         NOT NULL,
 assetid          text              NOT NULL,
         


        
2条回答
  •  执念已碎
    2021-01-23 15:14

    Assuming your date column holds different timestamps for each item, by using the ORDER BY clause:

    SELECT * FROM users WHERE userid=foo ORDER BY "date";
    

    However, if you inserted a large number of records in a single transaction, the date column value will probably be the same for all of them - if so, there is no way to tell which was inserted first (from the information given).

提交回复
热议问题