目录
1. 清空表
清空表:
TRUNCATE TABLE table_name;
清空表并还原自增id:
TRUNCATE TABLE raw_lte_cell RESTART IDENTITY;
2. 基本功能
postgresql基本功能:创建表、新增列、修改列字段名称、某列值自增或循环自增
https://blog.csdn.net/zsc201825/article/details/84285446
3. 按日期范围查询
https://blog.csdn.net/kmust20093211/article/details/48089105
1. select * from user_info where create_date >= '2015-07-01' and create_date < '2015-08-15’;
2. select * from user_info where create_date between '2015-07-01' and '2015-08-15’;
3. select * from user_info where create_date between to_date('2015-07-01','YYYY-MM-DD') and to_date('2015-08-15','YYYY-MM-DD’);
4.取最后一条:
SELECT * FROM table_name order by id desc limit 1;
5. shell/命令行连接方式:
psql -U user_name -d db_name -h ipadress -p 5432
6. 索引
语法:
单列索引:
CREATE INDEX index_name
ON table_name (column_name);
组合索引:
CREATE INDEX index_name
ON table_name (column1_name, column2_name);
原则:
- 不管是单列索引还是组合索引,该索引必须是在 WHEHE 子句的过滤条件中使用非常频繁的列。
- 如果只有一列被使用到,就选择单列索引,如果有多列就使用组合索引。
a. 创建btree索引:
CREATE INDEX idx_raw_lte_cell_start_time_end_time on raw_lte_cell (start_time, end_time);
b. 创建brin块索引
CREATE INDEX idx_raw_lte_cell_start_time_end_time on raw_lte_cell using brin (start_time, end_time);
c. 查看表索引:
/d tb_name;
d. 列出数据库中所有索引:
\di
e. 删除索引:
DROP INDEX index_name;