Skip to content

Sequelize does not generate correct SQL query when using the findAll query with a schema that contains fields with '.' characters. #9964

Closed

Description

@mbecker16

What you are doing?

I have a schema with fields such as 'foo.bar.baz'
Sequelize will generate the correct 'Create Table if not exist' query but will not generate a correct
'SELECT' query with this column name. The SELECT that gets generated from this is " SELECT foo.bar.baz from

where . The SELECT query should be "SELECT foo.bar.baz. As a result the db responds with an error, (Responding with error. SequelizeBaseError: ER_BAD_FIELD_ERROR: Unknown column 'foo.bar.baz' in 'field list') which is also misleading.

The following model will reproduce with mySQL db
{
id: {
type: sequelize.UUID,
primaryKey: true
},
'foo.bar.baz': sequelize.TEXT
}

     model.findAll({ where: {id: 123} }).then(
            items => {},
            error => {}
        );

What do you expect to happen?

SELECT foo.bar.baz, id FROM WHERE id = 123

What is actually happening?

SELECT foo.bar.baz, id FROM WHERE id = 123

Output, either JSON or SQL

Dialect: mysql
Database version: AWS Aurora
Sequelize version: 3.30

Activity

  1. knoxcard commented on Sep 28, 2018

    @knoxcard
    Contributor

    I think it needs to perhaps add apostrophes, like this?
    What about the table name?

    SELECT `foo.bar.baz`, `id` FROM `tablename` WHERE`id` = 123
    
  2. added
    type: bug
    on Oct 21, 2018
  3. sushantdhiman commented on Oct 21, 2018

    @sushantdhiman
    Contributor

    I have tagged this as a bug. May I know why you have dots in your column name?

  4. knoxcard commented on Oct 21, 2018

    @knoxcard
    Contributor

    It's one personal preference to do so. I personally never heard of it until @mbecker16 mentioned it.

    Here is a good reference.
    https://stackoverflow.com/questions/10229287/updating-a-mysql-column-that-contains-dot-in-its-name

  5. tsasaki609 commented on Nov 3, 2018

    @tsasaki609
    Contributor

    I am working on it, so please wait a little more. 😃

  6. mbecker16 commented on Nov 13, 2018

    @mbecker16
    Author

    Thanks @tsasaki609 for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions