SQLite Forum

Is the order conserved in a table from a VALUES clause?
Login
I have the following scenario (see fiddle [here](https://dbfiddle.uk/?rdbms=sqlite_3.27&fiddle=f7d210e86494cc5deaf1de0b7965a1a7)):

CREATE TABLE x
(
  val INT PRIMARY KEY,
  txt TEXT NOT NULL
);

Populate:

INSERT INTO x VALUES
(1, 'val_1'),
(2, 'val_2'),
(3, 'val_3'),
(4, 'val_4'),
(5, 'val_5'),
(6, 'val_6'),
(7, 'val_7');


SELECT
  x.val, x.txt
FROM
  x
JOIN
(
  SELECT ROW_NUMBER() OVER () AS rn, column1
  FROM 
  (VALUES (5), (6), (1))
) AS tab
ON x.val = tab.column1
ORDER BY tab.rn;

Result:

val 	txt
5 	val_5
6 	val_6
1 	val_1


Now, I want to know am I **_guaranteed_** to have the `ORDER` of my `VALUES` clause respected - no matter how big it gets? Will `ROW_NUMBER()` match the VALUES in tab in the order in which they are declared?

With PostgreSQL and `WITH ORDINALITY`, one can guarantee the order of the result. 

So, for SQLite, is this the case now and will it remain the case into the future?

If the behaviour is undefined, may I suggest that it be guaranteed - makes life a lot easier - and if one has entered the values in a particular order, it seems reasonable to respect that down the line - at least to me! Or else they would have been entered in a **different** order! 

Just a (respectful) thought! Rgs.
 
[link](https://dbfiddle.uk/?rdbms=sqlite_3.27&fiddle=f7d210e86494cc5deaf1de0b7965a1a7) again