Skip to content

Instantly share code, notes, and snippets.

@lfittl
Last active March 23, 2017 04:55
Show Gist options
  • Select an option

  • Save lfittl/9065920d2ecd1a4b017f to your computer and use it in GitHub Desktop.

Select an option

Save lfittl/9065920d2ecd1a4b017f to your computer and use it in GitHub Desktop.
require 'pg_query'
pp PgQuery.parse("SELECT * FROM x WHERE y = ?")
#<PgQuery:0x007f8cdaaaae10
@parsetree=
[{"SELECT"=>
{"distinctClause"=>nil,
"intoClause"=>nil,
"targetList"=>
[{"RESTARGET"=>
{"name"=>nil,
"indirection"=>nil,
"val"=>{"COLUMNREF"=>{"fields"=>[{"A_STAR"=>{}}], "location"=>7}},
"location"=>7}}],
"fromClause"=>
[{"RANGEVAR"=>
{"schemaname"=>nil,
"relname"=>"x",
"inhOpt"=>2,
"relpersistence"=>"p",
"alias"=>nil,
"location"=>14}}],
"whereClause"=>
{"AEXPR"=>
{"name"=>["="],
"lexpr"=>{"COLUMNREF"=>{"fields"=>["y"], "location"=>22}},
"rexpr"=>{"PARAMREF"=>{"number"=>0, "location"=>26}},
"location"=>24}},
"groupClause"=>nil,
"havingClause"=>nil,
"windowClause"=>nil,
"valuesLists"=>nil,
"sortClause"=>nil,
"limitOffset"=>nil,
"limitCount"=>nil,
"lockingClause"=>nil,
"withClause"=>nil,
"op"=>0,
"all"=>false,
"larg"=>nil,
"rarg"=>nil}}],
@query="SELECT * FROM x WHERE y = ?",
@warnings=[]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment