Man*_*hit 3 sql postgresql select
我对 postgres 返回的行的默认排序有点困惑。
postgres=# select * from check_user;
id | name
----+------
1 | x
2 | y
3 | z
4 | a
5 | c1\
6 | c2
7 | c3
(7 rows)
postgres=# update check_user set name = 'c1' where name = 'c1\';
UPDATE 1
postgres=# select * from check_user;
id | name
----+------
1 | x
2 | y
3 | z
4 | a
6 | c2
7 | c3
5 | c1
(7 rows)
Run Code Online (Sandbox Code Playgroud)
在任何更新之前,它返回按 id 排序的行,但更新后,顺序已更改。所以我的问题是,如果没有指定 order by,postgres 使用什么默认排序?
提前致谢。
SQL 表表示无序集。
SQL 结果集是无序的,除非您显式包含order by.
你的select没有order by。因此,行可以按任何顺序返回。即使运行相同的查询两次也会产生不同的顺序。