Tim*_*and 4 format postgresql floating-point rounding psql
如何设置数字显示格式psql?
我有许多 character varying和double precision列中select查询。我可以在每个数字列上使用to_char()或round(),但是对于许多列,这会使代码过于重复。
有捷径吗?例如,是否有任何psql会话设置,例如\pset numeric '9.9EEEEE'(我只是编造的,不要尝试使用它)。我无法在手册中快速找到此类设置:PostgreSQL: Documentation: psql。
例子:
-- Got this:
=# select bar from (values (123456789), (0.123456789), (0.000000123456789)) table_foo (bar);
bar
-------------------
123456789
0.123456789
0.000000123456789
-- I have to use this workaround:
=# select to_char(bar, '9.9EEEEE') as bar from (values (123456789), (0.123456789), (0.000000123456789)) table_foo (bar);
bar
----------
1.2e+08
1.2e-01
1.2e-07
-- I want this:
-- set some session settings, and then magically:
=# select bar from (values (123456789), (0.123456789), (0.000000123456789)) table_foo (bar);
bar
----------
1.2e+08
1.2e-01
1.2e-07
Run Code Online (Sandbox Code Playgroud)
没有其他可能性来指定格式数然后指定数字语言环境。值已在服务器端格式化,psql格式化为最终输出格式(表、html、csv),但值已格式化,并且psql不会尝试重新格式化(numericlocale例外)。我记得关于指定布尔类型输出格式的可能性的长期讨论,但仍然没有实际结果。psql没有强大的功能来生成丰富的报告。它应该是快速、安全和健壮的交互式客户端。虽然我在这方面有更大的可能性,但现代电子表格和报告工具更适合某些任务。
| 归档时间: |
|
| 查看次数: |
358 次 |
| 最近记录: |