Using Insert - Default in a condition expression ?? - Mailing list pgsql-general

From Postgres User
Subject Using Insert - Default in a condition expression ??
Date
Msg-id b88c3460909282325s861cdf2sd907757e4f307b2@mail.gmail.com
Whole thread Raw
Responses Re: Using Insert - Default in a condition expression ??
List pgsql-general
Hi,

I'm trying to write an INSERT INTO statement that will use a DEFAULT
value when an input parameter is null.

Here's the function that fails to compile.  I tried replacing Coalesce
with a Case statement but that fails as well.  Note that if you
replace the condition with a simple 'Default' it compiles
successfully.  Any ideas?


CREATE OR REPLACE FUNCTION "name_add" (
    p_name varchar,
    p_created_date date
) RETURNS integer AS
$body$
DECLARE
BEGIN
    INSERT INTO names
    (
        name,
        created_date
    )
    VALUES
    (
        p_name,
        Coalesce(p_created_date, DEFAULT)
    );
    Return 1;
END ;
$body$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;

pgsql-general by date:

Previous
From: Oleg Bartunov
Date:
Subject: Re: generic modelling of data models; enforcing constraints dynamically...
Next
From: Sim Zacks
Date:
Subject: Re: Using Insert - Default in a condition expression ??