【发布时间】:2015-04-17 23:45:19
【问题描述】:
我有一个复杂类型,其中包含另一个复杂类型的单个字段:
-- 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
具有复杂和非复杂类型字段的复杂类型:
-- 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
是否可以用嵌套的复杂类型测试复杂类型的空值?
-
是否可以在没有“空”嵌套复杂类型的情况下获得序列化复杂类型?
-- 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,,)
我正在运行 PostgreSQL 9.4.0,由 Visual C++ build 1800 编译,64 位 (Windows 7)。
【问题讨论】:
标签: sql postgresql null row plpgsql