1/* contrib/hstore/hstore--1.1--1.2.sql */
2
3-- complain if script is sourced in psql, rather than via ALTER EXTENSION
4\echo Use "ALTER EXTENSION hstore UPDATE TO '1.2'" to load this file. \quit
5
6
7-- A version of 1.1 was shipped with these objects mistakenly in 9.3.0.
8-- Therefore we only add them if we detect that they aren't already there and
9-- dependent on the extension.
10
11DO LANGUAGE plpgsql
12$$
13DECLARE
14  my_schema pg_catalog.text := pg_catalog.quote_ident(pg_catalog.current_schema());
15  old_path pg_catalog.text := pg_catalog.current_setting('search_path');
16BEGIN
17-- for safety, transiently set search_path to just pg_catalog+pg_temp
18PERFORM pg_catalog.set_config('search_path', 'pg_catalog, pg_temp', true);
19
20   PERFORM 1
21   FROM pg_proc p
22       JOIN  pg_depend d
23          ON p.proname = 'hstore_to_json_loose'
24            AND d.classid = 'pg_proc'::regclass
25            AND d.objid = p.oid
26            AND d.refclassid = 'pg_extension'::regclass
27       JOIN pg_extension x
28          ON d.refobjid = x.oid
29            AND  x.extname = 'hstore';
30
31   IF NOT FOUND
32   THEN
33        PERFORM pg_catalog.set_config('search_path', old_path, true);
34
35        CREATE FUNCTION hstore_to_json(hstore)
36        RETURNS json
37        AS 'MODULE_PATHNAME', 'hstore_to_json'
38        LANGUAGE C IMMUTABLE STRICT;
39
40        CREATE CAST (hstore AS json)
41          WITH FUNCTION hstore_to_json(hstore);
42
43        CREATE FUNCTION hstore_to_json_loose(hstore)
44        RETURNS json
45        AS 'MODULE_PATHNAME', 'hstore_to_json_loose'
46        LANGUAGE C IMMUTABLE STRICT;
47
48   END IF;
49
50PERFORM pg_catalog.set_config('search_path', old_path, true);
51END;
52
53$$;
54