Skip to content

Issues parsing a column named user #92

@chayim

Description

@chayim

First off thank you - I love this library!

In my case, I wrap several queries, and run them through a parser like a bunch of other folks. My simplified example looks like:

res, _ := pg_query.Parse(query)
stmt := res.Stmts[0].Stmt.GetSelectStmt()
for _, f := range stmt.GetTargetList() {
    sp := f.GetResTarget().GetVal().GetColumnRef().GetFields()[0]
    fmt.Println(sp.GetString_().Sval)
}

The following query of course, works: select username, password from foo where user = 'somehuman'

target_list:{res_target:{val:{column_ref:{fields:{string:{sval:\"username\"}} location:7}} location:7}} target_list:{res_target:{val:{column_ref:{fields:{string:{sval:\"password\"}} location:17}} location:17}} from_clause:{range_var:{relname:\"foo\" inh:true relpersistence:\"p\" location:31}} where_clause:{a_expr:{kind:AEXPR_OP name:{string:{sval:\">\"}} lexpr:{column_ref:{fields:{string:{sval:\"x\"}} location:41}} rexpr:{a_const:{ival:{ival:17} location:45}} location:43}} limit_option:LIMIT_OPTION_DEFAULT op:SETOP_NONE" time="2023-07-05T11:55:54+03:00" level=debug msg="column_ref:{fields:{string:{sval:\"username\"}} location:7

The second, I change username to user, when attempting to call f.GetResTarget().GetVal().GetColumnRef().GetFields()[0] as clearly there's an indexing issue, do the the following parsed version of the object.

target_list:{res_target:{val:{sqlvalue_function:{op:SVFOP_USER typmod:-1 location:7}} location:7}} target_list:{res_target:{val:{column_ref:{fields:{string:{sval:\"password\"}} location:13}} location:13}} from_clause:{range_var:{relname:\"foo\" inh:true relpersistence:\"p\" location:27}} where_clause:{a_expr:{kind:AEXPR_OP name:{string:{sval:\">\"}} lexpr:{column_ref:{fields:{string:{sval:\"x\"}} location:37}} rexpr:{a_const:{ival:{ival:17} location:41}} location:39}} limit_option:LIMIT_OPTION_DEFAULT op:SETOP_NONE"

Is this an underlying libpq issue? I would have assumed my query would parse, and I'd just have a column named user

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions