Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby tutorial for how to write stored procedures for PostgreSQL?

I have heard that one in PostgreSQL can write stored procedures in Ruby.

But I haven't been able to find more information about it teaching one how to actually do it.

Could someone recommend good sources for that.

Thanks

like image 294
never_had_a_name Avatar asked Aug 01 '10 02:08

never_had_a_name


2 Answers

Obviously, you need to install PL/Ruby. After that, you can write:

CREATE FUNCTION ruby_max(int4, int4) RETURNS int4 AS '
    if args[0].to_i > args[1].to_i
        return args[0]
    else
        return args[1]
    end
' LANGUAGE 'plruby';

Check its GitHub repository for installation instructions.

like image 200
Daniel O'Hara Avatar answered Oct 06 '22 22:10

Daniel O'Hara


Check this website: http://moulon.inra.fr/ruby/plruby.html , it has some nice examples.

like image 39
Frank Heikens Avatar answered Oct 06 '22 21:10

Frank Heikens