0

I'm using Postrgesql via python, but I'm getting an error on the following insertion, alleging that 'column "\ufeff61356169" does not exist'.

c_id = "\ufeff61356169"
chunk = "engine"

query = f"""
    INSERT INTO company_chunks(company_id, chunk)
    VALUES(`{c_id}`, `{chunk}`);
    """
c.execute(query)

>>>
DatabaseError: {'S': 'ERROR', 'V': 'ERROR', 'C': '42703', 'M': 'column "\ufeff61356169" does not exist', 'P': '88', 'F': 'parse_relation.c', 'L': '3514', 'R': 'errorMissingColumn'}

One key note: "\ufeff61356169" is the value which is to be inserted into the column. So the error confuses me. It's confusing the insertion value for the column, which should receive the insertion. Any thoughts?

Just to verify that everything else is in working order I made sure to check that my table was successfully created.

query = """
SELECT column_name 
FROM information_schema.columns 
WHERE table_name = 'company_chunks';
"""
c.execute(query)
c.fetchall()

>>>
(['company_id'], ['chunk'])

So the table does exist and it has the columns, which I'm trying to make insertions to. Where am I going wrong here?

Btw, I'm connecting to this database, which is stored in GCP, via the Cloud SQL Python Connector. However, this connector was able to create the table, so I believe the problem is specific to python syntax and/or Postgres.

Edit: For the sake of understanding what this table looks like, here's the creation query.

query= """
CREATE TABLE company_chunks 
    (
    company_id    VARCHAR(25)    NOT NULL,
    chunk    VARCHAR(100)    NOT NULL
    );
"""
c.execute(query)
conn.commit()

1 Answer 1

2

better to do it this way by using %s placeholder:

sql = "INSERT INTO company_chunks(company_id, chunk) VALUES (%s, %s)"
var = (c_id,chunk)
mycursor.execute(sql,var)
Sign up to request clarification or add additional context in comments.

1 Comment

That did it! I guess it was expecting a tuple payload.

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.