postgresql - Postgresql (pgAdmin 4) - How to change in system settings decimal separator from dots to commas
问题描述
In Poland we use comma instead of dot as decimal separator. My whole databases use commas and I have this error when I want to import data to postgrsql:
ERROR: invalid input syntax for type numeric: "0,000" CONTEXT: COPY Sheet1, line 2, column Sales quantity: "0,000" SQL state: 22P02
How can I change Postgresql settings so that it accepts commas instead of dots as decimal separator?
解决方案
您必须更改配置参数lc_numeric
。这可以通过 db 启动时的配置参数文件或在 sql 中即时发生(有关与参数交互的其他方式,请参阅相应的文档部分)。
要更改整个集群的设置,请使用:
ALTER SYSTEM lc_numeric TO 'pl_PL.UTF-8'; -- Check the original setting first !!!
对于一次性工作来说,这可能不是一个好主意(而且您可能无论如何都没有特权)。
以下步骤说明了如何在当前 sql 事务的数字格式的英美和波兰约定之间切换:
-- show the current setting. let's say it is 'en_US.UTF-8'. Remember/store for later.
show lc_numeric;
-- American style.
select to_char(123456789.8765, '999G999G999D99');
-- Set to Polish convention (group separator ' ', decimal: ',')
set lc_numeric to 'pl_PL.UTF-8';
-- Polish style
select to_char(123456789.8765, '999G999G999D99');
-- Restore original value
set lc_numeric to 'en_US.UTF-8';
在 Postgresql 12 上测试。文档、部分SET和Locale config中的更多详细信息。
推荐阅读
- php - 如何在 PHP 中更正此代码错误 - 尝试访问 null 类型值的数组偏移量?
- mongodb - 用于缓存的 Mongodb 索引与 Redis
- pyqt5 - 在任何情况下如何拉伸 QTableWidget 最后一列
- vue.js - 使 v-card 拉伸到父组件的底部
- java - 在下载管理器使文件/目录不存在之前删除文件/目录并重新创建
- dgl - 找不到“gin-supervised-contextpred”、“gin-supervised-edgepred”、“gin-supervised-infomax”的 DGL-LifeSci 训练代码?
- c# - 如何以 C# 形式设置 Powershell ExecutionPolicy?
- c# - 将简单的 SET 与 StackExchangeRedis 一起使用?
- optimization - 如何为每个决策变量指定区间?CPLEX
- r-markdown - Rmarkdown 缺少目录 HTML