定义NOT NULL变量
最近更新时间: 2025-02-18 16:02:00
postgres=# CREATE OR REPLACE FUNCTION f25() RETURNS VOID AS
postgres-# $$
postgres$# DECLARE
postgres$# v_int integer NOT NULL := 1;
postgres$# BEGIN
postgres$# RAISE NOTICE 'v_int = %',v_int;
postgres$# SELECT NULL INTO v_int;
postgres$# RAISE NOTICE 'v_int = %',v_int;
postgres$# END;
postgres$# $$
postgres-# LANGUAGE plpgsql;
CREATE FUNCTION
postgres=# SELECT f25();
NOTICE: v_int = 1
ERROR: null value cannot be assigned to variable "v_int" declared NOT NULL
CONTEXT: PL/pgSQL function f25() line 6 at SQL statement
postgres=#
定义为NOT NULL变量,则该变量受NOT NULL约束。