Column 'Mary' Does Not Exist

Column 'mary' does not exist

Use plain single quotes to delimit a string literal 'Mary' not smart quotes ‘Mary’

SQL WHERE - Column (value) does not exist

use single quote for string value because double quote means column name

SELECT * FROM pg_roles WHERE rolname='rom_tut'

Column doens't exists in PostgreSQL (WHERE column_name = column_value)

It's as simple as the wrong type of quote marks. You wanted:

SELECT * FROM grades 
WHERE subject = 'latin';

To explain:

  • Single quotes, like 'latin', are the standard way to write a string in standard SQL, and should work on all DBMSes.
  • Double quotes, in Postgres and some other DBMSes, are a way of quoting identifiers - so if your column name had a space in for some reason (there's not many good reasons to do it, but it's possible), then you might write SELECT * FROM grades WHERE "subject name" = 'latin' - "subject name" is the name of the column, 'latin' is a string.

Although double quotes are in the SQL standard, other DBMSes use different syntax for quoting identifiers, so may treat double quotes as an alternative for writing strings.

-- Postgres (also works in Microsoft SQL Server, but isn't the default style)
SELECT * FROM grades WHERE "subject name" = 'latin'
-- MySQL
SELECT * FROM grades WHERE `subject name` = 'latin'
-- Microsoft SQL Server
SELECT * FROM grades WHERE [subject name] = 'latin'

But if you always use single quotes for strings, and avoid names that need quoting, you'll run into fewer problems.

-- Works pretty much everywhere
SELECT * FROM grades WHERE subject = 'latin'

Error: column does not exist when in fact it does? why?

check your quote characters ...

AND r.type = 'long_form'

Use single quotes are for string constants.

psycopg error, column does not exist

The problems that cause this error are because you forgot to add a comma between {1!s} and {2!s}, and you also didn't escape the string 'someentry' so postgres thought it was a column name identifier.

The solution is to fix the syntax error and escape values. Here's the correct way to do that:

cur.execute(
'INSERT INTO mytable (ip_id, item) VALUES (%s, %s)',
(1, 'someentry')
)

If the table name is also a variable, since the table name is an identifier you need to use extension AsIs:

from psycopg2.extensions import AsIs

cur.execute(
'INSERT INTO %s (ip_id, item) VALUES (%s, %s)',
(AsIs('mytable'), 1, 'someentry')
)


Related Topics



Leave a reply



Submit