I have a complex type with a single field of another complex type:
-- Result: IS NULL = FALSE, IS NOT NULL = TRUE
-- Looks OK
CREATE TYPE bar_ok AS (id int);
CREATE TYPE foo_ok AS (val bar_ok);
CREATE OR REPLACE FUNCTION nulltest_ok()
returns foo_ok as
$$
DECLARE
_r foo_ok;
_a bool;
_b bool;
BEGIN
_a := _r IS NULL;
_b := _r IS NOT NULL;
RAISE NOTICE 'is null %', _a;
RAISE NOTICE 'is not null %', _b;
RETURN _r;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM nulltest_ok();
-- RESULT:
-- NOTICE: is null f
-- NOTICE: is not null t
Complex type with fields of complex and non-complex type:
-- Result: IS NULL = FALSE, IS NOT NULL = FALSE
-- Is that OK?
CREATE TYPE bar_bad AS (id int);
CREATE TYPE foo_bad AS (id int, val bar_bad);
CREATE OR REPLACE FUNCTION nulltest_bad()
returns foo_bad as
$$
DECLARE
_r foo_bad;
_a bool;
_b bool;
BEGIN
_a := _r IS NULL;
_b := _r IS NOT NULL;
RAISE NOTICE 'is null %', _a;
RAISE NOTICE 'is not null %', _b;
RETURN _r;
END;
$$ LANGUAGE plpgsql;
SELECT * FROM nulltest_bad();
-- RESULT:
-- NOTICE: is null f
-- NOTICE: is not null f
Is it possible to test null value of complex type with nested complex types?
Is it possible to get serialized complex type without "empty" nested complex type?
-- Type CREATE TYPE some_type AS ( id int, some_complex_type_here bar, name varchar ) -- Now - serialized complex type with nested complex type (null): (1,(),) -- Goal: (1,,)
I am running PostgreSQL 9.4.0, compiled by Visual C++ build 1800, 64-bit (Windows 7).