PostgreSQL向现有行添加更多值
我对SQL一点也不熟悉,希望有人能帮我PostgreSQL向现有行添加更多值,postgresql,Postgresql,我对SQL一点也不熟悉,希望有人能帮我 imss=# SELECT name, content from testdb where name = 'Test'; name | content ------+-------------------------------------------- Test | *@test1.com;*@test2.com;*@test3.com; (1 row) 如何向“内容”列添加更多值其中名称='Test' like
imss=# SELECT name, content from testdb where name = 'Test';
name | content
------+--------------------------------------------
Test | *@test1.com;*@test2.com;*@test3.com;
(1 row)
如何向“内容”列添加更多值<代码>其中名称='Test'
like *@test4.com;*@test5.com;@test5.com;
亲切问候,如果您将CSV存储为单列,那么您应该重新考虑您的设计
UPDATE testdb
SET content = content || ';@test4.com;*@test5.com;@test5.com'
WHERE name = 'Test';
如果内容是文本数组,则可以使用array\u APPEND
:
UPDATE testdb
SET content = ARRAY_APPEND(content, '@test4.com')
WHERE name = 'Test';
或者:
UPDATE testdb
SET content = content || ARRAY['@test4.com']
WHERE name = 'Test';
魔术谢谢,这正是我需要的。在GUI中添加地址将其作为上述格式存储在DB中,我猜这就是应用程序读取地址的方式。如果
content
是一个数组,则第一个查询也可以工作。| |
也适用于数组:@a_horse_和_no_名称谢谢,我不知道:)这是一个非常非常丑陋的数据库设计。阅读数据库规范化