@@ -106,6 +106,7 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
106106 statements = @tree . stmts . dup . to_a . map ( &:stmt )
107107 from_clause_items = [ ] # types: select, dml, ddl
108108 subselect_items = [ ]
109+ call_items = [ ] # CALL fn()
109110
110111 loop do
111112 statement = statements . shift
@@ -171,6 +172,8 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
171172 when :copy_stmt
172173 from_clause_items << { item : PgQuery ::Node . new ( range_var : statement . copy_stmt . relation ) , type : :dml } if statement . copy_stmt . relation
173174 statements << statement . copy_stmt . query
175+ when :call_stmt
176+ call_items << statement . call_stmt
174177 # The following statement types are DDL (changing table structure)
175178 when :alter_table_stmt
176179 case statement . alter_table_stmt . objtype
@@ -285,6 +288,7 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
285288 when :sub_link
286289 statements << next_item . sub_link . subselect
287290 when :func_call
291+ # See also CALL below
288292 subselect_items . concat ( next_item . func_call . args . to_ary )
289293 @functions << {
290294 function : next_item . func_call . funcname . map { |f | f . string . sval } . join ( '.' ) ,
@@ -299,6 +303,17 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
299303 end
300304 end
301305
306+ # CALL fn()
307+ next_item = call_items . shift
308+ if next_item
309+ # Treat as a sub-select. Note the difference in underscore in func_call versus the above.
310+ subselect_items . concat ( next_item . funccall . args . to_ary )
311+ @functions << {
312+ function : next_item . funccall . funcname . map { |f | f . string . sval } . join ( '.' ) ,
313+ type : :call
314+ }
315+ end
316+
302317 next_item = from_clause_items . shift
303318 if next_item && next_item [ :item ]
304319 case next_item [ :item ] . node
0 commit comments