Skip to content

Commit

Permalink
Fix search path for psql function
Browse files Browse the repository at this point in the history
This ensures that all calls of the function use the expected searchpath
and the tables of our schema can be found.
As our migration-import doesn't set the searchpath when inserting new
documents but uses fully qualified table names this leads to the job
failing as it is not finding the tables.

RISDEV-6261
  • Loading branch information
malte-laukoetter committed Jan 28, 2025
1 parent 3e6ab62 commit 57f0447
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE OR REPLACE FUNCTION update_eli_tables()
RETURNS trigger AS
$$
BEGIN
INSERT INTO norm_expression
VALUES (
-- see definition of dokumente.eli_norm_manifestation
((xpath(
'//*[local-name()="act"]/*[local-name()="meta"]/*[local-name()="identification"]/*[local-name()="FRBRExpression"]/*[local-name()="FRBRuri"]/@value'::text,
NEW.xml))[1])::text)
ON CONFLICT DO NOTHING;
INSERT INTO norm_manifestation
VALUES (
-- see definition of dokumente.eli_norm_manifestation
(regexp_replace(((xpath(
'(//*[local-name()="act"]/*[local-name()="meta"]/*[local-name()="identification"]/*[local-name()="FRBRManifestation"]/*[local-name()="FRBRuri"]/@value)'::text,
NEW.xml))[1])::text, '/[^/]*$'::text, ''::text)),
-- see definition of dokumente.eli_norm_expression
((xpath(
'//*[local-name()="act"]/*[local-name()="meta"]/*[local-name()="identification"]/*[local-name()="FRBRExpression"]/*[local-name()="FRBRuri"]/@value'::text,
NEW.xml))[1])::text)
ON CONFLICT DO NOTHING;
RETURN NEW;
END;
$$
LANGUAGE 'plpgsql' VOLATILE SET search_path from current;

0 comments on commit 57f0447

Please sign in to comment.