目錄
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;