Indicating DEFAULT values in INSERT statement

From: Postgres User <postgres(dot)developer(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Indicating DEFAULT values in INSERT statement
Date: 2011-08-09 22:57:46
Message-ID: CADecbQkgkzMvw__GDYawY=NDOgzJ4bmZF8=bC2PuTH9BC9U+sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

According to the docs, the DEFAULT keyword lets you explicitly insert a
field's default value in an INSERT statement.

From a db function, I'd like to force the use of default when an input
parameter is null. This syntax looks correct but fails to compile.

Any suggestions?

INSERT INTO public.test
(
userid, object_id, user_notes, object_status, created_ts
)
VALUES
(
p_userid, p_obj_id, p_user_notes, p_obj_status,
Case When p_created_ts Is Not Null Then p_created_ts Else DEFAULT
End
);

I tried replacing the Case statement as follows, but it fails also:
Coalesce(p_created_ts, DEFAULT)

Thanks

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ondrej Ivanič 2011-08-09 23:17:18 Postgres on SSD
Previous Message Tom Lane 2011-08-09 21:18:38 Re: Problem with planner