stats DB stored procs
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 25 Aug 2005 18:22:53 +0000 (18:22 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 25 Aug 2005 18:22:53 +0000 (18:22 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@1733 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/sql/Pg/stats/functions.sql [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/stats/functions.sql b/Open-ILS/src/sql/Pg/stats/functions.sql
new file mode 100644 (file)
index 0000000..b724010
--- /dev/null
@@ -0,0 +1,30 @@
+CREATE OR REPLACE FUNCTION dim_row_hash () RETURNS TRIGGER AS $func$
+       use Digest::MD5 qw/md5_hex/;
+
+       $_TD->{new}{id} =
+               md5_hex(
+                       join(   '' =>
+                               map {
+                                       defined $_TD->{new}{$_} ?
+                                               ( $_TD->{new}{$_} ) :
+                                               ()
+                               } sort grep {
+                                       $_ != 'id'
+                               } keys %{ $_TD->{new} }
+                       )
+               );
+
+       my $schema = spi_exec_query(<<" SQL")->{rows}[0]{nspname};
+         SELECT        nspname
+           FROM        pg_class c
+                       JOIN pg_namespace n ON (c.relnamespace = n.oid);
+       SQL
+
+       return 'SKIP' if (spi_exec_query(<<"    SQL")->{processed});
+         SELECT        1
+           FROM        $schema.$$_TD{relname}
+           WHERE       id = '$$_TD{new}{id}';
+       SQL
+
+       return 'MODIFY';
+$func$ LANGUAGE 'plperlu';