首页 > 解决方案 > 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?

标签: postgresqlpgadmin-4

解决方案


您必须更改配置参数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 上测试。文档、部分SETLocale config中的更多详细信息。


推荐阅读