pg学习_数据更新
来源:互联网 发布:统计局报表怎么填数据 编辑:程序博客网 时间:2024/05/20 09:24
数据更新1、插入语法结构highgo=# \h insertCommand: INSERTDescription: create new rows in a tableSyntax:[ WITH [ RECURSIVE ] with_query [, ...] ]INSERT INTO table_name [ ( column_name [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query } [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]单条记录插入highgo=# select * from test1; id | name ----+------(0 rows)highgo=# insert into test1 values(001,'adam');INSERT 0 1部分字段插入highgo=# insert into test1(id) values(002);INSERT 0 1highgo=# select * from test1; id | name ----+------ 1 | adam 2 | (2 rows)通过其他表插入记录highgo=# insert into test1(id,name)highgo-# select id,name from test2;INSERT 0 1highgo=# select * from test1; id | name ----+-------- 1 | adam 2 | 2 | lilith(3 rows)通过脚本插入[highgo@node1 ~]$ vi insert_test1.sqlinsert into test1 values(003,'eva');执行插入highgo=# \i insert_test1.sqlINSERT 0 1highgo=# select * from test1; id | name ----+-------- 1 | adam 2 | 2 | lilith 3 | eva(4 rows)2、更新操作语法结构highgo=# \h updateCommand: UPDATEDescription: update rows of a tableSyntax:[ WITH [ RECURSIVE ] with_query [, ...] ]UPDATE [ ONLY ] table_name [ * ] [ [ AS ] alias ] SET { column_name = { expression | DEFAULT } | ( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] ) } [, ...] [ FROM from_list ] [ WHERE condition | WHERE CURRENT OF cursor_name ] [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]highgo=# update test1 set name='adam' where id=2;UPDATE 2highgo=# select * from test1; id | name ----+------ 1 | adam 3 | eva 2 | adam 2 | adam(4 rows)利用子查询更新多列highgo=# update test2highgo-# set name=(select name from test1 where id=1),highgo-# id=(select id from test1 where name='adam')highgo-# where id=2;UPDATE 2highgo=# select * from test2; id | name ----+------ 1 | adam 1 | adam(2 rows)通过其他表的条件更新数据highgo=# update test1highgo-# set name=(select name from test2 where id =2)highgo-# where name='adam';UPDATE 2highgo=# select * from test1; id | name ----+-------- 3 | eva 1 | eva 2 | lilith 2 | lilith(4 rows)3、删除操作语法结构highgo=# \h deleteCommand: DELETEDescription: delete rows of a tableSyntax:[ WITH [ RECURSIVE ] with_query [, ...] ]DELETE FROM [ ONLY ] table_name [ * ] [ [ AS ] alias ] [ USING using_list ] [ WHERE condition | WHERE CURRENT OF cursor_name ] [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]highgo=# delete from test1 where id=2;DELETE 2highgo=# select * from test1; id | name ----+------ 3 | eva 1 | eva(2 rows)通过其他表的条件删除数据highgo=# delete from test1 where name in (select name from test2);DELETE 2highgo=# select * from test1; id | name ----+------(0 rows)
0 0
- pg学习_数据更新
- pg学习_数据查询
- pg学习_集合操作
- pg学习_函数类型
- pg学习_子查询
- pg学习_运算符,表达式
- pg学习_多表连接
- pg学习_基本表定义_创建表
- pg学习_基本表定义_数据类型
- pg学习_基本表定义_约束关系
- pg学习_基本表定义_修改表结构
- pg学习_视图、序列、触发器、存储过程
- 更新DBD-Pg模块
- PG学习记录
- pg(HGDB)学习总结
- ceph学习之PG
- PG学习异常总结篇:遇到并处理过的异常-持续更新
- PG数据向Kingbase移植
- 【IDE-Visual Studio】如何在使用vs调试如何才能不显示反汇编?
- Centos 系统折腾
- strtus2学习(7)自定义类型转换器
- LCT模板题
- Java transient关键字使用小记
- pg学习_数据更新
- 灰度直方图及直方图均衡化
- 单例模式的八种写法比较
- Dlib 实现人脸的68点检测
- 老哥稳,如何优雅的解决SSD的写入放大问题
- 14.Selenium2 自动化测试实战-基于Python语言-多窗口切换
- 1.3 Go 命令
- Python的创建型设计模式之建造者模式
- Hive SQL优化