文章目录
glance
import psycopg2
class Psql:
def __init__(self, dbname, user, password, host='localhost', port=5432):
dsn = f"dbname={dbname} user={user} password={password} host={host} port={port}"
self.conn = psycopg2.connect(dsn)
self.cursor = self.conn.cursor()
def __del__(self):
self.cursor.close()
self.conn.close()
def select(self, sql_string):
self.cursor.execute(sql_string)
return self.cursor.fetchall()
def run_sql(self, sql_string):
self

本文介绍了PostgreSQL的基本使用,包括glance、数据库和表格操作,如创建、删除表,插入、查询、更新和删除数据。还讨论了Python的psycopg2驱动,特别是any操作符的优势,并分享了在使用serial自增类型和强制删除database时的注意事项。
最低0.47元/天 解锁文章
1024

被折叠的 条评论
为什么被折叠?



