Re: force defaults - Mailing list pgsql-general

From Alban Hertroys
Subject Re: force defaults
Date
Msg-id CAF-3MvP+7Rb17u6wpzfa3-wnMi=WZLSLGRDHRdA0KSZ224ZD4g@mail.gmail.com
Whole thread Raw
In response to force defaults  (Willy-Bas Loos <willybas@gmail.com>)
List pgsql-general
On 12 September 2012 08:49, Willy-Bas Loos <willybas@gmail.com> wrote:
Hi,

I want to force deafults, and wonder about the performance.
The trigger i use (below) makes the query (also below) take 45% more time.
The result is the same now, but i do have a use for using the trigger (see "background info").

Isn't there a more efficient way to force the defaults (in the database) when the application layer explicitly inserts a NULL?

Perhaps a rewrite-rule on INSERT/UPDATE would serve your purpose better? You could just wrap the appropriate column with a coalesce-call, like you did in your trigger.

Even then, calling coalesce for each inserted/updated row is not free, of course.

You could also perform the replacing of NULL values in your PHP application. Probably better to handle this case in the database though.
--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

pgsql-general by date:

Previous
From: Kenaniah Cerny
Date:
Subject: CentOS initd Script
Next
From: "Albe Laurenz"
Date:
Subject: Re: Postgresql replication assistance