[英]JSON extract multiple columns PostgreSQL
我之前有一个问题: PostgreSQL 用正则表达式修剪文本字段(或其他)我得到了 a_horse_with_no_name 的精彩回答。 现在我有一个关于这个问题的额外问题。
所以这里是这个rextester https://rextester.com/SUWG96428 ,目标是将所有ID放在一个单独的列中。 有可能吗?
像这样:
+---+----+-------+-------+
| | id | ids_1 | ids_2 |
+---+----+-------+-------+
| 1 | 1 | 4202 | 4203 |
| 2 | 2 | 4204 | |
| 3 | 3 | 4201 | |
+---+----+-------+-------+
是的,您可以修改您的查询,如:
select
t.id,
right(((the_column::json->'itemID')->>0)::varchar, 4) as col1,
right(((the_column::json->'itemID')->>1)::varchar, 4) as col2,
right(((the_column::json->'itemID')->>2)::varchar, 4) as col3
from the_table t;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.