Skip to content

More informative column alias? #1

@mmkal

Description

@mmkal

Hi - love the library! I don't know if this is an issue per-se, but I got some output I wasn't expecting.

Given this is a "high-level" SQL parser, I was hoping to use it to tell me which columns of which tables queries referred to. It gets me closer, but further parsing is still needed. Example:

let sqlSurveyor = require("sql-surveyor")

let surveyor = new sqlSurveyor.SQLSurveyor(sqlSurveyor.SQLDialect.PLpgSQL)
let columns = surveyor.survey('select f.id from foo as f').getQueryAtLocation(0).outputColumns

console.log(columns)

This prints:

[
  OutputColumn {
    columnName: 'f.id',
    columnAlias: null,
    tableName: 'f',
    tableAlias: null
  }
]

Whereas I'd expect sql-surveyor to do the fiddly bits for me and figure out that f is an alias for the actual table foo, and that the implicit column alias (i.e. the column name that I'll get back from running this query on most clients) is id, so an output of

[
  OutputColumn {
    columnName: 'f.id',
    columnAlias: 'id',
    tableName: 'foo',
    tableAlias: 'f'
  }
]

I can figure that stuff out myself, by looking up 'f' in referencedTables, and parsing 'f.id' by splitting on '.', but I was hoping sql-surveyor would do some of that for me. Just wanted to check a) it isn't already done in a feature I haven't come across yet or b) whether you'd be open to adding that functionality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions