Förläng dina ansträngningar bara en liten bit, vad sägs om:
quote_1 = ("monkeys rock", "False")
quote_2 = ("donkeys rock", "True")
q_list = [ quote_1, quote_2]
print cur.mogrify("insert into posts VALUES(%s,%s::quotes[])",
("animals are good", q_list))
#
# added explicit cast to quotes[]->^^^^^^^^
Förklaring :
Om du kör:
insert into posts
VALUES('animals are good', ARRAY[
('monkeys rock', 'false'),
('donkeys rock', 'true')
]);
direkt i psql
du får:
regress=# insert into posts
regress-# VALUES('animals are good',ARRAY[
regress-# ('monkeys rock', 'false'),
regress-# ('donkeys rock', 'true')
regress-# ]);
ERROR: column "q" is of type quotes[] but expression is of type record[]
LINE 1: insert into posts VALUES('animals are good',ARRAY[('monkeys ...
^
HINT: You will need to rewrite or cast the expression.
Visst nog, tala om för Pg att din anonyma array är av typen quotes[]
gör susen:
regress=# insert into posts
regress-# VALUES('animals are good',ARRAY[
regress-# ('monkeys rock', 'false'),
regress-# ('donkeys rock', 'true')
regress-# ]::quotes[]);
INSERT 0 1
regress=# select * from posts;
body | q
------------------+--------------------------------------------------------
animals are good | {"(\"monkeys rock\",false)","(\"donkeys rock\",true)"}
(1 row)