gpt4 book ai didi

postgresql - 如何在postgresql中显示null、空字符串、空格?

转载 作者:行者123 更新时间:2023-12-03 08:10:32 28 4
gpt4 key购买 nike

执行以下语句创建数据库并创建表,然后插入 null 、空字符串和空格以及字符串 x

CREATE DATABASE test;
\c test;
CREATE TABLE test (
id numeric(3,0) PRIMARY KEY,
content varchar(255)
);
INSERT INTO test (id, content) VALUES (1, NULL);
INSERT INTO test (id, content) VALUES (2, '');
INSERT INTO test (id, content) VALUES (3, ' ');
INSERT INTO test (id, content) VALUES (4, 'x');

所有数据 - null 、空字符串、空格在选择时显示为相同的空白。

enter image description here

如何正确显示它们?

test=#  \pset null 'Unknown'
Null display is "Unknown".
test=# select * from test;
id | content
----+---------
1 | Unknown
2 |
3 |
4 | x
(4 rows)

遗留问题:如何区分空字符串 '' 和空白 ' '?设置一些内容以更好地显示空字符串 '' 和空白' ' 在 psql shell 中。

最佳答案

这就是我在 psql 中的做法:

test=> \pset null '(null)'
Null display is "(null)".
test=> SELECT id, '"' || content || '"' FROM test;
id │ ?column?
════╪══════════
1 │ (null)
2 │ ""
3 │ " "
4 │ "x"
(4 rows)

关于postgresql - 如何在postgresql中显示null、空字符串、空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70979921/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com