您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍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数组添加元素的方法的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。