0

I'm trying to do a select query on a psql DB. But my columnname is "Tagnaam", so case sensitive.

I'm trying this query:

cur.execute("SELECT Tagnaam FROM opc_taginstellingen")

I've read the solution would be to use double quotes on the column name, but that doesn't fix it.

What I also tried:

cur.execute("SELECT "Tagnaam" FROM opc_taginstellingen")
cur.execute("SELECT ""Tagnaam"" FROM opc_taginstellingen")
cur.execute("SELECT '"Tagnaam"' FROM opc_taginstellingen")

None of the above worked.

The error it gives:

    cur.execute("SELECT Tagnaam FROM opc_taginstellingen")
psycopg2.ProgrammingError: column "tagnaam" does not exist
LINE 1: SELECT Tagnaam FROM opc_taginstellingen
               ^

How can I solve this problem?

Thanks in advance.

1
  • 1
    It looks like you aren't properly escaping your quotes. Try cur.execute("SELECT \"Tagnaam\" FROM opc_taginstellingen") or cur.execute('SELECT "Tagnaam" FROM opc_taginstellingen') Commented Jul 20, 2015 at 16:04

2 Answers 2

5

Using "Tagnaam" and single quotes (' ') around the query should work:

cur.execute('SELECT "Tagnaam" FROM opc_taginstellingen')
Sign up to request clarification or add additional context in comments.

1 Comment

Actually it does provide a solution to the question asked. Thanks for the hint, I rephrased the wording to better match the answer format.
0

Postgresql and all databases (Oracle, Db2...) usually treat column names in a case-insensitive way, so it should no matter how do you write the field name in the query. Try first all in the psql client. If it works, you can add it to the python code, but be careful, if you use "" inside the string, you should write the string like 'string with "quotedString" inside". The case where the single quotes and double quotes swap can also happen.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.