在带有psycopg2的Postgresql中找不到自定义类型

在带有psycopg2的Postgresql中找不到自定义类型,postgresql,psycopg2,Postgresql,Psycopg2,简介: query = """INSERT INTO table (column names...) VALUES (%(integer1)s, %(date)s, %(integer2)s, %(custom1)s::customtype[], [...]);""" 我正在尝试使用Python/psycopg2以以下格式将数据插入Postgres: (integer, date, i

简介:

query = """INSERT INTO table (column names...) VALUES
            (%(integer1)s, %(date)s, %(integer2)s, 
            %(custom1)s::customtype[], [...]);"""
我正在尝试使用Python/psycopg2以以下格式将数据插入Postgres:

(integer, date, integer, customtype[], customtype[], customtype[], customtype[])
但是,当我尝试插入它们时,总是会出现以下错误:

““customtype[]”不存在”


我的设置如何:

query = """INSERT INTO table (column names...) VALUES
            (%(integer1)s, %(date)s, %(integer2)s, 
            %(custom1)s::customtype[], [...]);"""
我有一个记录我需要的数据的dict,比如:

data_dict = {'integer1':1, 'date': datetime(), 
             'integer2': 2, 'custom1':[(str, double, double),(str, double, double)], 
             'custom2':[(str, double, double),(str, double, double),(str, double, double)],
             'custom3':[(str, double, double),(str, double, double),(str, double, double)],
             'custom4':[(str, double, double)]}
每个自定义数组可以根据需要具有任意多个自定义元组

我已经为这些自定义元组创建了一个类型,如下所示:

"CREATE TYPE customtype AS (text, double precision, double precision)"
我已经创建了一个包含customtype[]列的表


到目前为止我所尝试的:

query = """INSERT INTO table (column names...) VALUES
            (%(integer1)s, %(date)s, %(integer2)s, 
            %(custom1)s::customtype[], [...]);"""
以及:

但这两个选项呈现相同的结果

最后一个问题:

如何使用Psycopg2在Postgresql中插入这些记录类型数组?

也许我完全误解了Postgresql的工作原理。我来自BigQuery记录/重复类型背景

附言:这就是我的疑问:

cursor.execute(query,data_dict)

问题是我在数据库中创建了类型

在Postgresql中引用自定义类型时,需要引用创建该类型的数据库以及该类型

像这样:

(%(dict_name)s)::"database_name".type
#or
CAST(%(dict_name)s as "database_name".type)

小心引用

问题是我在数据库中创建了类型

在Postgresql中引用自定义类型时,需要引用创建该类型的数据库以及该类型

像这样:

(%(dict_name)s)::"database_name".type
#or
CAST(%(dict_name)s as "database_name".type)
小心引用