PLRuby::Description::Function::SFRM (Class)

In: plruby.rb
Parent: Object

Function returning SET (SFRM Materialize)

The return type must be declared as SETOF

The function must call yield to return rows or return a String which must be a valid SELECT statement

For example to concatenate 2 rows create the function

   plruby_test=# CREATE FUNCTION tu(varchar) RETURNS setof record
   plruby_test-# AS '
   plruby_test'#    size = PL.column_name(args[0]).size
   plruby_test'#    res = nil
   plruby_test'#    PL::Plan.new("select * from #{args[0]}",
   plruby_test'#                 "block" => 50).each do |row|
   plruby_test'#       if res.nil?
   plruby_test'#          res = row.values
   plruby_test'#       else
   plruby_test'#          res.concat row.values
   plruby_test'#          yield res
   plruby_test'#          res = nil
   plruby_test'#       end
   plruby_test'#    end
   plruby_test'#    if res
   plruby_test'#       res.concat Array.new(size)
   plruby_test'#       yield res
   plruby_test'#    end
   plruby_test'# ' language 'plruby';
   CREATE FUNCTION
   plruby_test=#
   plruby_test=# select * from tt;
    a | b
   ---+----
    1 |  2
    3 |  4
    5 |  6
    7 |  8
    9 | 10
   (5 rows)

   plruby_test=# select * from tu('tt') as tbl(a int, b int, c int, d int);
    a | b  | c | d
   ---+----+---+---
    1 |  2 | 3 | 4
    5 |  6 | 7 | 8
    9 | 10 |   |
   (3 rows)

   plruby_test=#

[Validate]