sqliterg icon indicating copy to clipboard operation
sqliterg copied to clipboard

Sort keys of objects returned by `SELECT * FROM table` by creation order instead of dictionary order

Open thanhnguyen2187 opened this issue 1 year ago • 10 comments

Hi!

Suppose I have this table:

CREATE TABLE `folders` (
	`id` text PRIMARY KEY NOT NULL,
	`name` text NOT NULL,
	`position` real DEFAULT 1 NOT NULL,
	`updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
	`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL
);

And this data:

INSERT INTO `folders`(id, name, position)
VALUES ('default', 'Default', 0)
ON CONFLICT(id) DO NOTHING;

SELECT * FROM folders would return:

{
  "results": [
    {
      "success": true,
      "resultSet": [
        {
          "created_at": "2024-02-04 12:23:08",
          "id": "default",
          "name": "Default",
          "position": 0.0,
          "updated_at": "2024-02-04 12:23:08"
        }
      ]
    }
  ]
}

I think it should follow creation order`, which returns:

  • id
  • name
  • position
  • updated_at
  • created_at

It is the behavior of the behavior of sqlite3 as well:

default|Default|0.0|2024-02-04 12:54:32|2024-02-04 12:54:32

Thanks!

thanhnguyen2187 avatar Feb 04 '24 12:02 thanhnguyen2187