1

I am following a tutorial from here, and trying to adapt it to pass multiple column values. I've tried solving this by researching the error message but every time I've tried re-writing the values with a { I get a different set of errors. What am I doing wrong?

DataError: malformed array literal: "value1" LINE 1: ... public."Texas"(licensenum,businessowner) VALUES ('value1','... ^ DETAIL: Array value must start with "{" or dimension information.

My Code:

import psycopg2
conn = psycopg2.connect(host="localhost",database="postgres", user="postgres", password="supershinypwdhere")
cur = conn.cursor()
cur.executemany("insert into public.\"Texas\"(licensenum,businessowner) VALUES (%s,%s)", [('value1','value2'),('value3','value4')])
conn.commit()
cur.close()
conn.close()
3
  • Can you post your schema? Commented Jan 9, 2019 at 2:23
  • @Selcuk Im afraid I dont know how to do that. Is the CREATE statement sufficient? Commented Jan 9, 2019 at 3:24
  • Yes but never mind. I was going to check if one of the columns is an array but @klin got it already :) Commented Jan 9, 2019 at 3:37

1 Answer 1

1

The error message means that the columns licensenum and businessowner (or one of them) are arrays. Probably they should be simple text, then your program would work well. However, if you really want them to be arrays, then you should pass lists, not strings as arguments, e.g.:

cur.executemany(
    "insert into public.\"Texas\"(licensenum,businessowner) VALUES (%s,%s)", 
    [(['value1'],['value2']),(['value3'],['value4'])])
Sign up to request clarification or add additional context in comments.

1 Comment

went back and checked yep I had set the licensenum column to be an array...doh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.