stats DB stored procs
[Evergreen.git] / Open-ILS / src / sql / Pg / stats / functions.sql
1 CREATE OR REPLACE FUNCTION dim_row_hash () RETURNS TRIGGER AS $func$
2         use Digest::MD5 qw/md5_hex/;
3
4         $_TD->{new}{id} =
5                 md5_hex(
6                         join(   '' =>
7                                 map {
8                                         defined $_TD->{new}{$_} ?
9                                                 ( $_TD->{new}{$_} ) :
10                                                 ()
11                                 } sort grep {
12                                         $_ != 'id'
13                                 } keys %{ $_TD->{new} }
14                         )
15                 );
16
17         my $schema = spi_exec_query(<<" SQL")->{rows}[0]{nspname};
18           SELECT        nspname
19             FROM        pg_class c
20                         JOIN pg_namespace n ON (c.relnamespace = n.oid);
21         SQL
22
23         return 'SKIP' if (spi_exec_query(<<"    SQL")->{processed});
24           SELECT        1
25             FROM        $schema.$$_TD{relname}
26             WHERE       id = '$$_TD{new}{id}';
27         SQL
28
29         return 'MODIFY';
30 $func$ LANGUAGE 'plperlu';