Select with multiple conditions and AND does not work with postgresql
var query = {
text: 'SELECT * FROM advertisement WHERE (brand_class = ($1) AND product_class = ($2)) ',
values: [brand_class,product_class]
};
const client = await pool.connect();
const res = await client.query(query);
I does not work with pg, but it works by directly querying postgresql.: SELECT * FROM advertisement WHERE (brand_class ='body_cosmetic' AND product_class ='skin_tone');
This one works: var query = { text: 'SELECT * FROM advertisement WHERE product_class =($1)', values: product_class };
But AND or other operator is not well handled by pg....
Is there an error? What do “does not work” and “not well handled” mean?
Thanks @charmander for your quick answer.
I've and advertisement table that contains product_class and brand_class elements.
Let's say product_class = product_class_1 & brand_class = brand_class_1
When I built my query with: var query = { text: 'SELECT * FROM advertisement WHERE product_class =($1)', values: product_class_1 }; Corresponding advertisement is well returned
When I built my query with: var query = { text: 'SELECT * FROM advertisement WHERE brand_class =($1)', values: brand_class_1 }; Corresponding advertisement is well returned
When I built my query with: var query = { text: 'SELECT * FROM advertisement WHERE (brand_class = ($1) AND product_class = ($2)) ', values: [brand_class_1,product_class_1] }; Nothing is returned.
When I directly requests postgre: SELECT * FROM advertisement WHERE (brand_class =brand_class_1 AND product_class =product_class_1);
Corresponding advertisement is well returned.
I don't understand why WHERE with multiple conditions (AND) does not return anything.
Thx for your help !