A
A
AlmazKayum2018-05-03 23:01:54
Python
AlmazKayum, 2018-05-03 23:01:54

How to make a SELECT with two conditions?

Good afternoon.
Stuck on a simple select query

def get_referal(self, chat_id):
        with self.conn:
            self.cursor.execute('SELECT chat_id FROM profile WHERE ref = %s AND comp_name NOT IN ("No name");',
                                (chat_id,))
            return self.cursor.fetchall()

Throws the following error
psycopg2.ProgrammingError: column "No name" does not exist
LINE 1: ...rofile WHERE ref = 442965 AND comp_name NOT IN ("No name")...

Variants
comp_name != "No name"
and
NOT comp_name IN ("No name")'
also give the same error. Allegedly, the "No name" field does not exist. Well, this is the value of the field, and not the field itself ...
Help, tell me, what am I stupid about?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Almaz Kayum, 2018-05-03
@AlmazKayum

Everything, he asked the question, he decided.
Who cares who will have the same error, you need to take out the value of the field in tuple

self.cursor.execute('SELECT chat_id FROM profile WHERE ref = %s AND comp_name != %s;', (chat_id, "No name"))

F
freeexec, 2018-05-03
@freeExec

Use single quotes'No name'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question