select folder_name  -- varchar
from ags_secured_endpoint_definition;

返回:
Utilities
Utilities
UtilityServices
*** ROOT ***
Midstream
EP
EP
EP
EP
EP
EP
Midstream
Culture
Culture
Culture
Culture
Culture
Culture
CustomUtilities
Basin
Basin
EP
EP
EP

排序后得到意外结果(“*ROOT*”):
select folder_name
from ags_secured_endpoint_definition
ORDER BY folder_name;

返回:
Basin
Basin
Culture
Culture
Culture
Culture
Culture
Culture
CustomUtilities
EP
EP
EP
EP
EP
EP
EP
EP
EP
Midstream
Midstream
*** ROOT ***
Utilities
Utilities
UtilityServices

最佳答案

这取决于您的排序,您可以使用

SHOW lc_collate;

显然,排序规则在排序时忽略空格和星号,因此*** ROOT ***的排序方式与ROOT类似。
如果不喜欢,可以选择其他排序规则,例如二进制:
SELECT folder_name
FROM ags_secured_endpoint_definition
ORDER BY folder_name COLLATE "C";

关于sql - 如何在PostgreSQL中对包含星号的VARCHAR列进行排序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53712278/

10-11 02:44