Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using star in the select of a subquery, the columns aren't available to queries making use of the subquery #377

Open
lalitkapoor opened this issue Oct 11, 2017 · 0 comments

Comments

@lalitkapoor
Copy link

lalitkapoor commented Oct 11, 2017

Notice that user.id is used in the select of the limit subQuery in the working example. In the one that errors user.star() is used in the select of the limit subQuery.

Works

sql.define({name: 'user', columns: ['id','name','email', 'lastLogin']})
var limit = user.subQuery('limit-users').select(user.id)
limit.toString() // (SELECT "user".* FROM "user") "limit-users"
sql.select(limit.id, sql.constant(true).as("c")).from(limit).toString() // SELECT "limit-users"."id", TRUE AS "c" FROM (SELECT "user"."id" FROM "user") "limit-users"

Errors

sql.define({name: 'user', columns: ['id','name','email', 'lastLogin']})
var limit = user.subQuery('limit-users').select(user.star())
// ALSO results in error: var limit = user.subQuery('limit-users')
limit.toString() // (SELECT "user".* FROM "user") "limit-users"
sql.select(limit.id, sql.constant(true).as("c")).from(limit).toString()
AssertionError [ERR_ASSERTION]: Error while trying to add a non-existant node to a query
    at constructor.Node.add (/lalitkapoor/pg-team/node_modules/sql/lib/node/index.js:17:3)
    at constructor.Node.addAll (/lalitkapoor/pg-team/node_modules/sql/lib/node/index.js:78:10)
    at constructor.select (/lalitkapoor/pg-team/node_modules/sql/lib/node/query.js:98:12)
    at Sql.select (/lalitkapoor/pg-team/node_modules/sql/lib/index.js:51:16)
    at repl:1:5
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)
@lalitkapoor lalitkapoor changed the title when using star in the select of a subquery, the columns aren't available to queries making use of the sub-query when using star in the select of a subquery, the columns aren't available to queries making use of the subquery Oct 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant