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

Incorrect deparse on calling stored procedures with indirection #113

Closed
herwinw opened this issue Oct 24, 2018 · 1 comment · Fixed by #116
Closed

Incorrect deparse on calling stored procedures with indirection #113

herwinw opened this issue Oct 24, 2018 · 1 comment · Fixed by #116

Comments

@herwinw
Copy link
Contributor

herwinw commented Oct 24, 2018

Stored procedures can return records with named columns:

2018-10-24 11:34 qnetdb=> \df XXX
                                                      List of functions
 Schema | Name  | Result data type |        Argument data types           |  Type  
--------+-------+------------------+--------------------------------------+--------
 public |  WWW  | record           | XXX, OUT YYY bigint, OUT ZZZ boolean | normal

It is possible to get specific columns with indirection, basicly wrapping the call to the stored procedure in parentheses and treating it like something with columns:

SELECT (WWW(1)).ZZZ

This is being parsed:

irb(main):009:0> pp PgQuery.parse('SELECT (WWW(1)).ZZZ').tree[0]
{"RawStmt"=>
  {"stmt"=>
    {"SelectStmt"=>
      {"targetList"=>
        [{"ResTarget"=>
           {"val"=>
             {"A_Indirection"=>
               {"arg"=>
                 {"FuncCall"=>
                   {"funcname"=>[{"String"=>{"str"=>"www"}}],
                    "args"=>
                     [{"A_Const"=>
                        {"val"=>{"Integer"=>{"ival"=>1}}, "location"=>13}}],
                    "location"=>8}},
                "indirection"=>[{"String"=>{"str"=>"zzz"}}]}},
            "location"=>7}}],
       "op"=>0}}}}

(This is why I called this "indirection", I really had no idea what it was called before)

But deparsing this drops the parentheses:

irb(main):010:0> PgQuery.parse('SELECT (WWW(1)).ZZZ').deparse
=> "SELECT www(1)\"zzz\""

This is still valid SQL, but is interpreted as SELECT www(1) AS zzz

@herwinw
Copy link
Contributor Author

herwinw commented Oct 24, 2018

Yes, I might have a look at it later this week

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

Successfully merging a pull request may close this issue.

1 participant