0

code:

const query = `SELECT DISTINCT :attribute FROM "users"`

sequelize.query(query { replacements: { attribute: attributes[0] } });

result (generated by sequelize):

SELECT DISTINCT 'locale' FROM "users"

how can i pass attribute to the query without single quotes or with double quotes ?

1 Answers1

0

Placeholders like :attribute represent query parameters. You can't use them to build a dynamic query.

If you need to change which column you're looking at, you could set query to SELECT DISTINCT ${attributes[0]} FROM "users" instead, but definitely make sure that attributes[0] cannot contain user input or your code will be vulnerable to SQL injection.

dmfay
  • 2,417
  • 1
  • 11
  • 22