Postgres SQL - 没有保留创建类型的游标
Postgres SQL - CURSOR WITHOUT HOLD FOR CREATE TYPE
我正在尝试使用 Python & psycopg2
在我的 Postgres 服务器中创建枚举
这是我的查询:
CREATE TYPE parser_type AS ENUM (
'regex',
'delimiter',
'column',
'json'
);
当我从 IDE 执行它时它工作正常,但是当我尝试从我的代码执行此查询时它引发异常
这是执行代码
def execute_statment(
self,
statment,
statment_params=None,
):
try:
self.connect()
cursor_id = uuid.uuid4().hex
with self.connection.cursor(
cursor_id,
) as cursor:
cursor.execute(
statment,
statment_params,
)
self.connection.commit()
except Exception as exception:
if self.connection is not None:
self.connection.rollback()
finally:
self.disconnect()
当我执行查询时出现异常
psycopg2.errors.SyntaxError: syntax error at or near "CREATE"
LINE 1: ...0bbe4cc0b7d0b9d44f74a378" CURSOR WITHOUT HOLD FOR CREATE TYPE
cursor
(name=None, cursor_factory=None, scrollable=None, withhold=False)
Return a new cursor object using the connection.
If name is specified, the returned cursor will be a server side cursor (also known as named cursor). Otherwise it will be a regular client side cursor.
错误消息告诉您不能将服务器端游标用于 运行 DDL 语句,因此不要为 cursor()
方法指定参数。
我正在尝试使用 Python & psycopg2
在我的 Postgres 服务器中创建枚举这是我的查询:
CREATE TYPE parser_type AS ENUM (
'regex',
'delimiter',
'column',
'json'
);
当我从 IDE 执行它时它工作正常,但是当我尝试从我的代码执行此查询时它引发异常
这是执行代码
def execute_statment(
self,
statment,
statment_params=None,
):
try:
self.connect()
cursor_id = uuid.uuid4().hex
with self.connection.cursor(
cursor_id,
) as cursor:
cursor.execute(
statment,
statment_params,
)
self.connection.commit()
except Exception as exception:
if self.connection is not None:
self.connection.rollback()
finally:
self.disconnect()
当我执行查询时出现异常
psycopg2.errors.SyntaxError: syntax error at or near "CREATE"
LINE 1: ...0bbe4cc0b7d0b9d44f74a378" CURSOR WITHOUT HOLD FOR CREATE TYPE
cursor
(name=None, cursor_factory=None, scrollable=None, withhold=False)Return a new cursor object using the connection.
If name is specified, the returned cursor will be a server side cursor (also known as named cursor). Otherwise it will be a regular client side cursor.
错误消息告诉您不能将服务器端游标用于 运行 DDL 语句,因此不要为 cursor()
方法指定参数。