Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 博士后按错误的顺序排序_Postgresql_Postgresql 11 - Fatal编程技术网

Postgresql 博士后按错误的顺序排序

Postgresql 博士后按错误的顺序排序,postgresql,postgresql-11,Postgresql,Postgresql 11,Postgres按错误结果排序: postgres=# SELECT (url) FROM posts_post ORDER BY url; url -------------------------------------------------------------------------------------------------- ----------------------------

Postgres按错误结果排序:

postgres=# SELECT (url) FROM posts_post ORDER BY url;
                                               url
--------------------------------------------------------------------------------------------------
 -----------------------------------------------------------------------------------------
 http://nautil.us/issue/70/variables/aging-is-a-communication-breakdown
 https://github.com/felixse/FluentTerminal
 http://www.bbc.com/future/story/20160408-the-ancient-peruvian-mystery-solved-from-space
 http://www.graffathon.fi/2016/presentations/additive_slides.pdf
(4 rows)
正如你所看到的,这是一个问题。它排序不正确

我使用Python和psycopg2将解析后的结果保存在Postgres中,并指出,我无法测试排序,这导致Postgres返回order by时出现错误

UPD:复制:

CREATE TABLE test_post ("id" serial NOT NULL PRIMARY KEY, "title" text NOT NULL, "url" text NOT NULL, "created" timestamp with time zone NOT NULL);

INSERT INTO test_post (title, url, created) VALUES ('Aging Is', 'http://nautil.us/issue/70/variables/aging-is-a-communication-breakdown', NOW()) ON CONFLICT DO NOTHING;

INSERT INTO test_post (title, url, created) VALUES ('Untrusted – a user', 'https://github.com/felixse/FluentTerminal', NOW()) ON CONFLICT DO NOTHING;

INSERT INTO test_post (title, url, created) VALUES ('Artyping (1939)', 'http://www.bbc.com/future/story/20160408-the-ancient-peruvian-mystery-solved-from-space', NOW()) ON CONFLICT DO NOTHING;

INSERT INTO test_post (title, url, created) VALUES (' Applying the Universal', 'http://www.graffathon.fi/2016/presentations/additive_slides.pdf', NOW()) ON CONFLICT DO NOTHING;

SELECT (url) FROM test_post ORDER BY url;
x86_64-pc-linux-gnu上的PostgreSQL 11.2 Debian 11.2-1.pgdg90+1,由gcc Debian 6.3.0-18+deb9u编译
1 6.3.0 20170516,64位

假设您正在使用UTF8编码,指定排序规则而不是接受默认值应该可以解决您的直接问题。这是否正确取决于应用程序

有几种不同的方法可以指定排序规则。您可以在初始化数据库集群、创建数据库、运行查询等时指定它。有关更多详细信息,请参阅文档中的

CREATE TABLE test_post (
    "id" serial NOT NULL PRIMARY KEY, 
    "title" text NOT NULL, 
    "url" text collate ucs_basic NOT NULL, 
    "created" timestamp with time zone NOT NULL
);

INSERT INTO test_post (title, url, created) VALUES 
('Aging Is', 'http://nautil.us/issue/70/variables/aging-is-a-communication-breakdown', NOW()) ON CONFLICT DO NOTHING;
INSERT INTO test_post (title, url, created) VALUES 
('Untrusted – a user', 'https://github.com/felixse/FluentTerminal', NOW()) ON CONFLICT DO NOTHING;
INSERT INTO test_post (title, url, created) VALUES 
('Artyping (1939)', 'http://www.bbc.com/future/story/20160408-the-ancient-peruvian-mystery-solved-from-space', NOW()) ON CONFLICT DO NOTHING;
INSERT INTO test_post (title, url, created) VALUES 
(' Applying the Universal', 'http://www.graffathon.fi/2016/presentations/additive_slides.pdf', NOW()) ON CONFLICT DO NOTHING;

SELECT (url) FROM test_post ORDER BY url;

http://nautil.us/issue/70/variables/aging-is-a-communication-breakdown
http://www.bbc.com/future/story/20160408-the-ancient-peruvian-mystery-solved-from-space
http://www.graffathon.fi/2016/presentations/additive_slides.pdf
https://github.com/felixse/FluentTerminal

:小于s,因此它正确排序http:应该在所有https:之前。@thebjorn最初我也这么认为,但底部有两行以http开头。编辑您的问题,然后粘贴复制问题的create table、insert和select语句。标记Postgres版本。使用您的复制限制集so 4(而不是33行)显示结果。不管怎样,Postgres 11.1对我来说是有效的。排序并没有问题:一些排序规则会忽略非字母或数字的字符。