#openGauss #入门 #安装 #数据库 #开源
知识来源:docs-opengauss.osinfra.cn/zh/
SELECT操作
以下Python程序显示了如何从上述示例中创建的COMPANY表中获取和显示记录:
sql复制代码#!/usr/bin/python
import psycopg2
conn = psycopg2.connect(database="testdb", user="openGauss", password="xxxxxxxx", host="127.0.0.1", port="26000")
cur = conn.cursor()
cur.execute("SELECT id, name, address, salary from COMPANY")
rows = cur.fetchall()
for row in rows:
print("ID = ", row[0])
print("NAME = ", row[1])
print("ADDRESS = ", row[2])
print("SALARY = ", row[3])
conn.close()
执行上述程序时,会返回以下结果:
ini复制代码ID =, 1
NAME =, Paul
ADDRESS =, California
SALARY =, 20000.0
ID =, 2
NAME =, Allen
ADDRESS =, Texas
SALARY =, 15000.0
ID =, 3
NAME =, Teddy
ADDRESS =, Norway
SALARY =, 20000.0
ID =, 4
NAME =, Mark
ADDRESS =, Rich-Mond
SALARY =, 65000.0
#openGauss #入门 #安装 #数据库 #开源