Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

PostgreSQL error when aggregate and group by custom column with camel-cased columnName #74

Open
masitko opened this issue Feb 3, 2016 · 2 comments
Labels

Comments

@masitko
Copy link

masitko commented Feb 3, 2016

There is a problem when using PostgreSQL and trying to aggregate and group data by column with custom camel-cased columnName.
For an example:

module.exports = {
  schema: true,
  attributes: {
    ip: {
      type: 'string',
    },
    host: {
      type: 'string',
    },
    count: {
      type: 'integer',
      defaultsTo: 1
    },
    user: {
      model: 'User',
      columnName: 'userId',
    }
  }
};

If we try to group users by userId column:

 UserLogin.find().sum('count').groupBy('userId')

created statement will trigger two errors in PostgreSQL:

SELECT userId as group0, CAST(SUM("userlogin"."count") AS float) AS count FROM "public"."userlogin" AS "userlogin"   GROUP BY userId

as we can see userId is missing required in this case double quotes.

@masitko masitko changed the title PostgreSQL when aggregate and group by custom column with camel-cased columnName PostgreSQL error when aggregate and group by custom column with camel-cased columnName Feb 3, 2016
@particlebanana
Copy link
Contributor

@masitko in this case what is the outcome when running:

UserLogin.find().sum('count').groupBy('user')

The point of the columnName is so that the mapping on the backend can perform this for you. You should only use the defined attributes you supply in queries.

@masitko
Copy link
Author

masitko commented Apr 11, 2016

@particlebanana This is the query produced by your statement:

SELECT userId as group0, CAST(SUM("userlogin"."count") AS float) AS count FROM "public"."userlogin" AS "userlogin"   GROUP BY user

Column was created properly with requested name 'userId'
I'm using latest releases of sails-postgresql and waterline-sequel

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants