更新
This commit is contained in:
@ -689,3 +689,14 @@ COPY tcn_stat_sales_volume_total FROM '/home/edbdata/tcn_stat_sales_volume_total
|
||||
|
||||
|
||||
|
||||
#### 手动创建分区
|
||||
|
||||
```sql
|
||||
select 'CREATE TABLE tcn_stat_algorithm_data_fltn_'||"FLT_NBR"|| ' PARTITION OF "TCN_STAT_ALGORITHM_DATA_FLTN" FOR VALUES IN (''' || "FLT_NBR"||''');'
|
||||
from (
|
||||
select distinct"FLT_NBR"::varchar from "TCN_STAT_ALGORITHM_DATA" where "FLT_DT" between '20190101' and '20191231'
|
||||
EXCEPT
|
||||
select high_value from all_tab_partitions where table_name = '"TCN_STAT_ALGORITHM_DATA_FLTN"'
|
||||
)
|
||||
```
|
||||
|
||||
|
@ -1,45 +1,121 @@
|
||||
连接数据库, 默认的用户和数据库是postgres
|
||||
|
||||
```
|
||||
psql -U user -d dbname
|
||||
```
|
||||
|
||||
切换数据库,相当于mysql的use dbname
|
||||
\c dbname
|
||||
列举数据库,相当于mysql的show databases
|
||||
\l
|
||||
列举表,相当于mysql的show tables
|
||||
\dt
|
||||
查看表结构,相当于desc tblname,show columns from tbname
|
||||
\d tblname
|
||||
|
||||
\di 查看索引
|
||||
```
|
||||
\c dbname
|
||||
```
|
||||
|
||||
列举数据库,相当于mysql的show databases
|
||||
|
||||
```
|
||||
\l
|
||||
```
|
||||
|
||||
列举表,相当于mysql的show tables
|
||||
|
||||
```
|
||||
\dt
|
||||
```
|
||||
|
||||
查看表结构,相当于desc tblname,show columns from tbname
|
||||
|
||||
```
|
||||
\d tblname
|
||||
```
|
||||
|
||||
查看索引
|
||||
|
||||
```
|
||||
\di
|
||||
```
|
||||
|
||||
创建数据库:
|
||||
create database [数据库名];
|
||||
删除数据库:
|
||||
drop database [数据库名];
|
||||
*重命名一个表:
|
||||
alter table [表名A] rename to [表名B];
|
||||
*删除一个表:
|
||||
drop table [表名];
|
||||
|
||||
*在已有的表里添加字段:
|
||||
```
|
||||
create database [数据库名];
|
||||
```
|
||||
|
||||
删除数据库:
|
||||
|
||||
```
|
||||
drop database [数据库名];
|
||||
```
|
||||
|
||||
重命名一个表:
|
||||
|
||||
```
|
||||
alter table [表名A] rename to [表名B];
|
||||
```
|
||||
|
||||
删除一个表:
|
||||
|
||||
```
|
||||
drop table [表名];
|
||||
```
|
||||
|
||||
在已有的表里添加字段:
|
||||
|
||||
```
|
||||
alter table [表名] add column [字段名] [类型];
|
||||
*删除表中的字段:
|
||||
```
|
||||
|
||||
删除表中的字段:
|
||||
|
||||
```
|
||||
alter table [表名] drop column [字段名];
|
||||
*重命名一个字段:
|
||||
```
|
||||
|
||||
重命名一个字段:
|
||||
|
||||
```
|
||||
alter table [表名] rename column [字段名A] to [字段名B];
|
||||
*给一个字段设置缺省值:
|
||||
```
|
||||
|
||||
给一个字段设置缺省值:
|
||||
|
||||
```
|
||||
alter table [表名] alter column [字段名] set default [新的默认值];
|
||||
*去除缺省值:
|
||||
```
|
||||
|
||||
去除缺省值:
|
||||
|
||||
```
|
||||
alter table [表名] alter column [字段名] drop default;
|
||||
```
|
||||
|
||||
在表中插入数据:
|
||||
|
||||
```
|
||||
insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......);
|
||||
```
|
||||
|
||||
修改表中的某行某列的数据:
|
||||
|
||||
```
|
||||
update [表名] set [目标字段名]=[目标值] where [该行特征];
|
||||
```
|
||||
|
||||
删除表中某行数据:
|
||||
|
||||
```
|
||||
delete from [表名] where [该行特征];
|
||||
delete from [表名];--删空整个表
|
||||
```
|
||||
|
||||
创建表:
|
||||
|
||||
```
|
||||
create table ([字段名1] [类型1] <references 关联表名(关联的字段名)>;,[字段名2] [类型2],......<,primary key (字段名m,字段名n,...)>;);
|
||||
```
|
||||
|
||||
|
||||
|
||||
```
|
||||
\copyright 显示 PostgreSQL 的使用和发行条款
|
||||
\encoding [字元编码名称]
|
||||
显示或设定用户端字元编码
|
||||
@ -48,4 +124,6 @@ create table ([字段名1] [类型1] <references 关联表名(关联的字段名
|
||||
提示用户设定内部变数
|
||||
\password [USERNAME]
|
||||
securely change the password for a user
|
||||
\q 退出 psql
|
||||
\q 退出 psql
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user