??: 大部分結(jié)尾要加引號(hào) 開頭要加 \
enter bd:
????psql -h host_name -p port_name db_name user_name
quit database: ?\q
search all db tables: ? ?\dt
search table frame:???? \d table_name
alter the column type of table:
????ALTER TABLE table_name ALTER COLUMN column_name TYPE type_name;
alter table_name:
? ? ALTER TABLE table_name RENAME TO new_name;
add column in a table:
? ? ALTER TABLE ?table_name ADD column_name dataType;
alter the column_type of a column in table:
? ? ALTER TABLE table_name ALTER COLUMN column_name TYPE dataType;
delete all data of a table:
? ? DELETE FROM table_name;
delete some data of a table:
? ? eg: DELETE FROM table_name WHERE time in (SELECT time from table_name ORDER BY time limit 3);
used in python:
import psycopg2
conn= psycopg2.connect(database='imd', password='imd', user='imd', host='192.168.3.24', port='5432')
cur= conn.cursor()
sql= "SELECT * FROM coins_1m"
df= pd.read_sql(sql, conn,)
cur.close()
conn.close()