-
Notifications
You must be signed in to change notification settings - Fork 12
/
unit--5--6.sql.in
38 lines (32 loc) · 1.22 KB
/
unit--5--6.sql.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
GRANT SELECT ON unit_prefixes, unit_units TO PUBLIC;
CREATE FUNCTION unit_load()
RETURNS VOID
LANGUAGE plpgsql
AS $$BEGIN
DELETE FROM unit_prefixes WHERE dump IS NOT TRUE;
CREATE TEMP TABLE tmp_prefixes (LIKE unit_prefixes) ON COMMIT DROP;
COPY tmp_prefixes (prefix, factor, definition, dump) FROM '@MODULEDIR@/unit_prefixes.data';
INSERT INTO unit_prefixes
SELECT * FROM tmp_prefixes t WHERE NOT EXISTS
(SELECT prefix FROM unit_prefixes u WHERE u.prefix = t.prefix);
DROP TABLE tmp_prefixes;
DELETE FROM unit_units WHERE dump IS NOT TRUE;
CREATE TEMP TABLE tmp_units (LIKE unit_units) ON COMMIT DROP;
COPY tmp_units (name, unit, shift, definition, dump) FROM '@MODULEDIR@/unit_units.data';
INSERT INTO unit_units
SELECT * FROM tmp_units t WHERE NOT EXISTS
(SELECT name FROM unit_units u WHERE u.name = t.name);
DROP TABLE tmp_units;
END;$$;
COMMENT ON FUNCTION unit_load() IS 'Loads/upgrades the unit_units and unit_prefixes contents from the data files on disk';
SELECT unit_load();
CREATE FUNCTION unit_at_double(unit, text)
RETURNS double precision
SET search_path = @extschema@
AS '$libdir/unit', 'unit_at_double'
LANGUAGE C IMMUTABLE STRICT;
CREATE OPERATOR @@ (
leftarg = unit,
rightarg = text,
procedure = unit_at_double
);