Using Insert - Default in a condition expression ??

From: Postgres User <postgres(dot)developer(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Using Insert - Default in a condition expression ??
Date: 2009-09-29 06:25:23
Message-ID: b88c3460909282325s861cdf2sd907757e4f307b2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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;

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2009-09-29 06:44:24 Re: Using Insert - Default in a condition expression ??
Previous Message Oleg Bartunov 2009-09-29 04:33:50 Re: generic modelling of data models; enforcing constraints dynamically...