代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
description: please input using description
author: justbk
date: 2022/7/26
modify_records:
- 2022/7/26 justbk create this file
"""
import os
import sys
PSYCOPG2_ROOT = '/home/zhoubin/code/openGauss-connector-python-psycopg2/output/'
sys.path.insert(0, PSYCOPG2_ROOT)
import psycopg2
connector_args = {
'database': 'postgres',
'user': 'test',
'password': 'Zhoubin@123',
'host': '20.20.20.52',
'port': '10101'
}
tinyint_type = psycopg2.extensions.new_type((5545,), 'tinyint', lambda s, conn_or_curs: int(s))
psycopg2.extensions.register_type(tinyint_type, None)
def test_connect():
conn = None
try:
conn = psycopg2.connect(**connector_args)
curs = conn.cursor()
curs.execute('drop table if exists t1;')
curs.execute('create table t1(col tinyint);')
curs.execute('insert into t1 values (%s);', (255,))
curs.execute('select * from t1;')
x = curs.fetchone()
print(type(x[0]), x)
except Exception as exp:
print('print error:%s'%(exp))
finally:
if conn is not None:
conn.close()
test_connect()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。