PostgreSQL中的collations
2020-11-13 09:08 abce 阅读(1094) 评论(0) 编辑 收藏 举报与Oracle相比,PostgreSQL对collation的支持依赖于操作系统。
以下是基于Centos7.5的测试结果
1 2 3 | $ env | grep LC $ env | grep LANG LANG=en_US.UTF-8 |
使用initdb初始化集群的时候,就会使用这些操作系统的配置。
1 2 3 4 5 6 7 8 9 10 11 12 | postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (4 rows ) postgres=# |
在新建数据库的时候,可以指定数据库的默认的callation:
1 2 3 4 5 6 | postgres=# create database abce with LC_COLLATE = "en_US.UTF-8" ; CREATE DATABASE postgres=# create database abce2 with LC_COLLATE = "de_DE.UTF-8" ; ERROR: new collation (de_DE.UTF-8) is incompatible with the collation of the template database (en_US.UTF-8) HINT: Use the same collation as in the template database , or use template0 as template. postgres=# |
但是,指定的collation必须是与template库兼容的。或者,使用template0作为模板。
1 | $ localectl list-locales |
也可以登录postgres后查看:
1 | postgres=# select * from pg_collation ; |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)