py-postgresql 基本操作
###创建连接
详细config配置参见官方文档中Connection Keywords部分
|
|
表创建
|
|
插入
|
|
查询
|
|
查询结果遍历/取值方式,结果为list结构
整行遍历
1234567for row in rs:print(row)> ('Jack Johnson', Decimal('85000'), datetime.date(1962, 11, 23), datetime.date(1990, 3, 5))> ('Debra McGuffer', Decimal('52000'), datetime.date(1973, 3, 4), datetime.date(2002, 1, 14))> ('Barbara Smith', Decimal('86000'), datetime.date(1965, 2, 24), datetime.date(2005, 7, 19))> ('John Johnson', Decimal('92000'), datetime.date(1950, 12, 10), datetime.date(1998, 4, 23))输出每行指定位置的值
12345678--下表从0开始for row in rs:print(row[0])> Jack Johnson> Debra McGuffer> Barbara Smith> John Johnson输出每行指定字段的值
1234567for row in rs:print(row['employee_name'])> Jack Johnson> Debra McGuffer> Barbara Smith> John Johnson迭代行中的key-value
12345678row = db.prepare("select * from employee").first()for k, v in row.items():print(k + "=" + str(v))> employee_name=Jack Johnson> employee_salary=85000> employee_dob=1962-11-23> employee_hire_date=1990-03-05
更新
|
|