question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Raw query with named substitution parameters gets quoted parameters

See original GitHub issue

I’m using sequelize to perform a simple raw query:

    var queryStr = 'SELECT * FROM :tableName WHERE :deletionColumn > 0 LIMIT :limit;';

    return self.connection.query(queryStr, {
        replacements: {
            tableName: self.name,
            deletionColumn: self.options.deletionColumn,
            limit: self.options.limit
        }
    }).then(function (rowsToDelete) {
        _.each(rowsToDelete, function (row) {
            log.debug('Preparing to delete row: ', row);
        });
    });

The resulting query however, is (from the sequelize logs):

Executing (default): SELECT * FROM 'test' WHERE 'deleted' > 0 LIMIT 421;

The generated query is invalid (table name must not be quoted).

Are there any options I can pass that’ll disable the quoting? I’m using MySQL 5.6 here.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:33 (12 by maintainers)

github_iconTop GitHub Comments

12reactions
AZS-99commented, Aug 24, 2021

Almost 7 years and still nothing … Any update on this apart from the cricket in the background?

8reactions
corybillcommented, Mar 1, 2019

Yeah… this is a super old thread, but NOT having this actually eliminates me from being able to use this node module. This is a feature available in basically every other module out there and they mostly all use the same syntax too.

? - params ?? - table / column names

Sure, I could hack around in my code to fix this, but why should I when I can use another node module that won’t force me too? This is a missing feature!

Are you open to allowing a PR for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid single quotes in sequelize query with ...
As a workaround I created the query and the sort order by separately and then concatenate them as follow: const query= `SELECT *...
Read more >
Raw Queries - Sequelize
Replacements in a query can be done in two different ways, either using named parameters (starting with : ), or unnamed, represented by...
Read more >
Passing parameters to SQL queries - Psycopg
Passing parameters to a SQL statement happens in functions such as Cursor.execute() by using %s placeholders in the SQL statement, and passing a...
Read more >
Running parameterized queries | BigQuery - Google Cloud
To use a timestamp in a query parameter, the underlying REST API takes a value of type TIMESTAMP in the format YYYY-MM-DD HH:MM:SS.DDDDDD...
Read more >
Raw queries - Manual | Sequelize
Replacements in a query can be done in two different ways, either using named parameters (starting with : ), or unnamed, represented by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found