insertion of nested array of custom in table for postgres

核能气质少年 提交于 2021-01-07 01:23:45

问题


command = (

CREATE TYPE belongings AS (
   item TEXT,
   quantity INTEGER
)

CREATE TYPE student AS ( 
   name TEXT,
   id  INTEGER,
   bag belongings[]
)

CREATE TABLE studentclass( 
    date DATE NOT NULL,
    time TIMESTAMPTZ NOT NULL, 
    PRIMARY KEY (date, time), 
    class student
)
)

Can i ask how to do insert for this in postgres psycog2? thank you.

When i put the insert as insert_sql = "INSERT INTO studentclass (date, time, class) VALUES (%s,%s,%s)"

error output is DETAIL: Cannot cast type text[] to belongings[] in column

I don't think i just cast it with "::belongings[]" in the INSERT statement as it is a nested.

My earlier asked question for a simpler table.

Unable to insert nested record in postgres

来源:https://stackoverflow.com/questions/64922416/insertion-of-nested-array-of-custom-in-table-for-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!