I keep getting this
error: psycopg2.ProgrammingError: column "someentry" does not exist.
The error indicates that the column someentry
does not exist when someentry
is not a column it's just a value to enter into the db.
Here is the code that gives the error:
cur.execute('INSERT INTO {0!s} (ip_id, item) VALUES ({1!s}{2!s})'.format('mytable',1,'someentry'))
Here is how I create my table:
tablename = 'mytable'
command = """
CREATE TABLE IF NOT EXISTS {} (
ip_id SERIAL PRIMARY KEY,
item VARCHAR(255) NOT NULL
)
""".format(tablename)
cur.execute(command)
You have to use single quotes within the query.
I received the same type of error from this
cur.execute('insert into my_table(id, name, horse_type, horse_code, horse_name) values(default, %s, 3, %s, "Mary Wonder")', [e[0], e[1]])
it produced
Traceback (most recent call last):
File "process_horse.py", line 11, in <module>
[e[0], e[1]])
psycopg2.ProgrammingError: column "Mary Wonder" does not exist
LINE 2: ', "Mary Wonder")
^
Obviously it is data, not a column name, like you said.
When I changed it to
cur.execute("insert into my_table(id, name, horse_type, horse_code, horse_name) values(default, %s, 3, %s, 'Mary Wonder')",[e[0], e[1]])
it worked with no errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With