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

"Between" and "In" operator doe not have "AEXPR" ? #66

Closed
carolfly86 opened this issue Aug 8, 2017 · 4 comments
Closed

"Between" and "In" operator doe not have "AEXPR" ? #66

carolfly86 opened this issue Aug 8, 2017 · 4 comments

Comments

@carolfly86
Copy link

carolfly86 commented Aug 8, 2017

Hi,
I'm not sure if this is a feature or bug. I noticed that for "Between" and "IN" operators in where clause the parse tree does not contain the "AEXPR" key. Whereas for "=" operator there's the 'AEXPR' key
For example:

=> "select id from t where id between 3 and 4"
>> pp PgQuery.parse(q).parsetree[0]
{"SELECT"=>
  {"targetList"=>
    [{"RESTARGET"=>
       {"val"=>{"COLUMNREF"=>{"fields"=>["id"], "location"=>7}},
        "location"=>7}}],
   "fromClause"=>
    [{"RANGEVAR"=>
       {"relname"=>"t", "inhOpt"=>2, "relpersistence"=>"p", "location"=>15}}],
   "whereClause"=>
    {nil=>
      {"name"=>["BETWEEN"],
       "lexpr"=>{"COLUMNREF"=>{"fields"=>["id"], "location"=>23}},
       "rexpr"=>
        [{"A_CONST"=>{"val"=>3, "location"=>34, "type"=>"integer"}},
         {"A_CONST"=>{"val"=>4, "location"=>40, "type"=>"integer"}}],
       "location"=>26}},
   "op"=>0}}



>> q='select id from t where id =3'
=> "select id from t where id =3"
>> pp PgQuery.parse(q).parsetree[0]
{"SELECT"=>
  {"targetList"=>
    [{"RESTARGET"=>
       {"val"=>{"COLUMNREF"=>{"fields"=>["id"], "location"=>7}},
        "location"=>7}}],
   "fromClause"=>
    [{"RANGEVAR"=>
       {"relname"=>"t", "inhOpt"=>2, "relpersistence"=>"p", "location"=>15}}],
   "whereClause"=>
    {"AEXPR"=>
      {"name"=>["="],
       "lexpr"=>{"COLUMNREF"=>{"fields"=>["id"], "location"=>23}},
       "rexpr"=>{"A_CONST"=>{"val"=>3, "location"=>27, "type"=>"integer"}},
       "location"=>26}},
   "op"=>0}}

@lfittl lfittl closed this as completed in bd1aba2 Aug 8, 2017
@lfittl
Copy link
Member

lfittl commented Aug 8, 2017

@carolfly86 Thanks for the report - that is indeed a bug, and I just fixed it in bd1aba2

I will probably stamp a new release soon, but if helpful I can also make a quick bugfix release just for this - let me know if that'd be helpful.

Also just as a note, if you are developing something new: .parsetree is the legacy and deprecated method to access the tree. There is an updated format under .tree that matches what we get from Postgres / libpg_query itself, and I would recommend using that if possible.

@carolfly86
Copy link
Author

Thanks @lfittl I can wait for the new release.

@lfittl
Copy link
Member

lfittl commented Aug 10, 2017

@carolfly86 Released 0.13.2 now which contains this fix - thanks again for reporting!

@carolfly86
Copy link
Author

thanks for fixing it!

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

2 participants