Skip to content

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

Open

Description

@lalitkapoor

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)

Activity

  1. 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[/+] on Oct 11, 2017
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions