【发布时间】:2018-11-07 14:40:38
【问题描述】:
执行我的代码时,我收到如下错误:
File "c:/not/test/xmlDB.py", line 27, in <module>
element.getAttribute("kodATC")
psycopg2.DataError: value too long for type character varying(255)
我的python代码是:
for element in rc:
if element.getAttribute("rodzajPreparatu") == "ludzki":
if len(element.getAttribute("kodATC")) > 50:
print(len(element.getAttribute("kodATC")))
print(element.getAttribute("kodATC"))
cur.execute("INSERT INTO leki VALUES (%s, %s, %s, %s, %s, %s, %s, %s,
%s, %s)",
(element.getAttribute("id"),
element.getAttribute("nazwaProduktu"),
element.getAttribute("nazwaPowszechnieStosowana"),
element.getAttribute("moc"),
element.getAttribute("postac"),
element.getAttribute("podmiotOdpowiedzialny"),
element.getAttribute("typProcedury"),
element.getAttribute("numerPozwolenia"),
element.getAttribute("waznoscPozwolenia"),
element.getAttribute("kodATC")
))
并且我的 Postgres 数据库中“kodATC”列的长度设置为 (255)。
打印值和长度的部分打印以下输出:
63
V01AA05;V01AA02;V01AA04;V01AA11;V01AA20;V01AA10;V01AA08;V01AA01
所以它显然不超过 (255)。 但是,当我在 pgAdmin 中执行以下查询时,它工作得很好:
INSERT INTO public.leki VALUES (100085341,'Novo-Helisen Depot','Wyciągi
alergenowe roztoczy kurzu domowego','-','zawiesina do wstrzykiwań','Allergopharma GmbH & Co. KG','NAR','00011','Bezterminowy','V01AA05;V01AA02;V01AA04;V01AA11;V01AA20;V01AA10;V01AA08;V01AA01');
【问题讨论】:
标签: python postgresql psycopg2