SQL语句
创建数据库
create database tyk;
显示所有数据库: \l;
切换数据库: \c +name;
显示该数据库的所有表: \d +tablename;
导入数据
1
2
3
4
5
6
7
8
9
10create table data(
update_time date,
id text,
title text,
price numeric,
sale_count int,
comment_count int,
店名 text
);
\copy data from 'G:\PostgreSQLData\数据可视化微专业_体验课资料\美妆数据.csv' with csv header;查看数据
1
2
3select * from data;
select id, title, price from data limit 10;
select * from data where id is null limit 10;删除数据
1
delete from data where sale_count is null;
例子
1 | create table OD2Array( |
psycopg2库
1 | conn = pg.connect(database, user, password, host, port) |
cursor对象
1 | cur = conn.cursor() # 创建cursor |