-
Notifications
You must be signed in to change notification settings - Fork 1
/
nan_value.sql
43 lines (40 loc) · 1.14 KB
/
nan_value.sql
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
39
40
41
42
43
--
-- This function is meant to be replaced by the user if necessary,
-- to allow user-defined handling of CBOR types with no direct analogs in JSON.
--
-- https://tools.ietf.org/html/rfc8949#section-6.1
--
CREATE OR REPLACE FUNCTION cbor.nan_value()
RETURNS jsonb
LANGUAGE plpgsql
AS $$
BEGIN
RAISE EXCEPTION 'NaN value has no direct analog in JSON.'
USING HINT = 'Replace cbor.nan_value() with user-defined function returning a substitue value, e.g. JSON null, if NaN values are expected and needs to be handled.',
DETAIL = 'See: https://github.com/truthly/pg-cbor/blob/master/FUNCTIONS/nan_value.sql for examples on such user-defined functions.';
END;
$$;
--
-- For inspiration, below are some alternative handlers for NaN values.
--
-- WARNING:
-- Please understand that returning a substitute value will introduce
-- a new class of possible bugs due to ambiguity, which might be OK
-- or dangerous, depending on the situation.
--
/*
CREATE OR REPLACE FUNCTION cbor.nan_value()
RETURNS jsonb
LANGUAGE sql
AS $$
SELECT 'null'::jsonb;
$$;
*/
/*
CREATE OR REPLACE FUNCTION cbor.nan_value()
RETURNS jsonb
LANGUAGE sql
AS $$
SELECT '"NaN"'::jsonb;
$$;
*/