PostgreSQL数组添加元素的方法-创新互联
                                            创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

这篇文章主要介绍PostgreSQL数组添加元素的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
PostgreSQL数组怎么添加元素
1、首先是插入数组数据,有两种方式
推荐:PostgreSQL教程
# 方式1
postgres=# insert into t_kenyon(items) values('{1,2}');
INSERT 0 1
postgres=# insert into t_kenyon(items) values('{3,4,5}');
INSERT 0 1
# 方式2
postgres=# insert into t_kenyon(items) values(array[6,7,8,9]);
INSERT 0 1
postgres=# select * from t_kenyon;id |   items  
----+-----------
  1 | {1,2}
  2 | {3,4,5}
  3 | {6,7,8,9}
(3 rows)2、数据删除
postgres=# delete from t_kenyon where id = 3; DELETE 1 postgres=# delete from t_kenyon where items[1] = 4; DELETE 0 postgres=# delete from t_kenyon where items[1] = 3; DELETE 1
3、数据更新(往数组内添加元素)
# 往后追加
postgres=# update t_kenyon set items = items||7;
UPDATE 1
postgres=# select * from t_kenyon;id |  items 
----+---------
  1 | {1,2,7}
(1 row)
postgres=# update t_kenyon set items = items||'{99,66}';
UPDATE 1
postgres=# select * from t_kenyon;
id |      items      
----+------------------
  1 | {1,2,7,55,99,66}
(1 row)
# 往前插
postgres=# update t_kenyon set items = array_prepend(55,items) ;
UPDATE 1
postgres=# select * from t_kenyon;
id |        items       
----+---------------------
  1 | {55,1,2,7,55,99,66}
(1 row)以上是PostgreSQL数组添加元素的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联-成都网站建设公司行业资讯频道!
文章标题:PostgreSQL数组添加元素的方法-创新互联
分享地址:http://www.scyingshan.cn/article/dieses.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 