Giter VIP home page Giter VIP logo

postgresql-plruby's Introduction

PL/ruby

PL/Ruby is a loadable procedural language for the PostgreSQL database system that enables the Ruby language to create functions and trigger procedures.

Prerequisite

  • ruby 1.8.6
  • postgresql >= 7.3

If you are using old PostgreSQL, all headers need to be installed. Command (see INSTALL in the directory postgresql-7.x.y)

    make install-all-headers

Installation

    ruby extconf.rb
    make
    make install

You may need to specify some of the following extconf.rb options:

    --with-pg-config=<location of the pg_config command of PostgreSQL>

Specifies the location of pg_config. e.g. --with-pg-config=/usr/local/bin/pg_config

    --with-greenplum

Builds plruby for Greenplum instead of PostgreSQL.

    --disable-conversion

By default plruby tries to convert a postgres type to a ruby class. This option gives the possibility to disable all conversions.

   --with-suffix=<suffix to add>

Specifies a suffix to add to the extension module file. e.g. ruby extconf.rb --with-suffix=_geo will create plruby_geo.so.

    --with-safe-level

Lowers the safe level which the plruby functions are run under. (default: 12; meaning the maximum)

    --with-timeout=<seconds>

Sets the timeout for each function call. (default: none)

    --with-main-safe-level

Lowers the safe level which the main thread waiting for timeouts is run under. (default: 3) This option is read only when --with-timeout is given.

Test (and examples)

WARNING: if plruby was compiled without --disable-conversion you must FIRST run make install before make test.

    make test

This will run the following three commands:

    ( cd test/plt; runtest )
    ( cd test/plp; runtest )
    ( cd test/range; runtest )

And if you do not specify the option --disable-conversion, make test will run the following three commands, too:

    ( cd test/conv_bitstring; runtest )
    ( cd test/conv_geometry; runtest )
    ( cd test/conv_network; runtest )

The database plruby_test is created and then destroyed. Don't use it if you have such a database.

Now you are ready to create the PL/Ruby language in PostgreSQL.

Since the pg_language system catalog is private to each database, the new language can be created only for individual databases, or in the template1 database. In the latter case, it is automatically available in all newly created databases.

The commands to create the new language are:

CREATE FUNCTION plruby_call_handler () RETURNS language_handler
    AS '$libdir/plruby'
    LANGUAGE C;

CREATE OR REPLACE LANGUAGE plruby
    HANDLER  plruby_call_handler;

Documentation

see plruby.rd and plruby.html

Development

New releases and sources can be obtained from https://github.com/pg-plruby-ug/postgresql-plruby

License

This extension module is copyrighted free software by Guy Decoux.

You can redistribute it and/or modify it under the same term as Ruby.

Authors and Contributors

postgresql-plruby's People

Contributors

koizumistr avatar knu avatar szymonlipinski avatar devrimgunduz avatar tfoldi avatar clivecrous avatar tsenying avatar

Stargazers

Joseph Wecker avatar Noboru Saito avatar

Watchers

James Cloos avatar Noboru Saito avatar  avatar

postgresql-plruby's Issues

conv_geometry test fails with PG9.6 and Ruby2.4 on Ubuntu

test.out is like this:

set client_min_messages = 'WARNING';
create table pl_box (
data box, barea float, boverlaps bool, boverleft bool, boverright bool,
bleft bool, bright bool
);
create or replace function box_val(box[]) returns setof pl_box as '
b1 = Box.new(2.5,2.5,1.0,1.0)
b2 = Box.new(2.0,2.0,2.5,2.5)
b3 = Box.new(3.0,3.0,5.0,5.0)
args[0].each do |b|
yield [b, b.area, b.overlap?(b1), b.overleft?(b2),
b.overright?(b2), b.left?(b3), b3.right?(b)]
end
' language 'plruby';
select * from
box_val('{(2.0,2.0,0.0,0.0);(1.0,1.0,3.0,3.0);(2.5,2.5,2.5,3.5);(3.0,3.0,3.0,3.0)}'::box[]);
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

conv_bitstring test fails with PG9.6 and Ruby2.4 on Ubuntu

test.out is like this:

create table bit_op (
b0 bit(8), b1 bit(8), band bit(8), bor bit(8),
bxor bit(8), bnot0 bit(8), bnot1 bit(8)
);
create function bt(integer, integer) returns bit_op as '
b0 = BitString.new(args[0], 8)
b1 = BitString.new(args[1], 8)
[b0, b1, b0 & b1, b0 | b1, b0 ^ b1, ~b0, ~b1]
' language 'plruby';
select * from bt(12, 24);
b0 | b1 | band | bor | bxor | bnot0 | bnot1
----------+----------+----------+----------+----------+----------+----------
00001100 | 00011000 | 00001000 | 00011100 | 00010100 | 11110011 | 11100111
(1 row)

select * from bt(12, 32);
b0 | b1 | band | bor | bxor | bnot0 | bnot1
----------+----------+----------+----------+----------+----------+----------
00001100 | 00100000 | 00000000 | 00101100 | 00101100 | 11110011 | 11011111
(1 row)

select * from bt(15, 278);
b0 | b1 | band | bor | bxor | bnot0 | bnot1
----------+----------+----------+----------+----------+----------+----------
00001111 | 00010110 | 00000110 | 00011111 | 00011001 | 11110000 | 11101001
(1 row)

create function be(integer) returns setof integer as '
BitString.new(args[0], 8).each {|i| yield i}
' language 'plruby';
select * from be(12);
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.