@@ -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
@@ -289,6 +292,7 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
289292 when :sub_link
290293 statements << next_item . sub_link . subselect
291294 when :func_call
295+ # See also CALL below
292296 subselect_items . concat ( next_item . func_call . args . to_ary )
293297 @functions << {
294298 function : next_item . func_call . funcname . map { |f | f . string . sval } . join ( '.' ) ,
@@ -303,6 +307,17 @@ def load_objects! # rubocop:disable Metrics/CyclomaticComplexity
303307 end
304308 end
305309
310+ # CALL fn()
311+ next_item = call_items . shift
312+ if next_item
313+ # Treat as a sub-select. Note the difference in underscore in func_call versus the above.
314+ subselect_items . concat ( next_item . funccall . args . to_ary )
315+ @functions << {
316+ function : next_item . funccall . funcname . map { |f | f . string . sval } . join ( '.' ) ,
317+ type : :call
318+ }
319+ end
320+
306321 next_item = from_clause_items . shift
307322 if next_item && next_item [ :item ]
308323 case next_item [ :item ] . node
0 commit comments