Re: Using Insert - Default in a condition expression ??

From: brent_despain(at)selinc(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Using Insert - Default in a condition expression ??
Date: 2009-09-29 14:15:04
Message-ID: OF1F917042.CC263F52-ON88257640.004DA473-87257640.004E48DF@selinc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Don't know if this will get attached to the conversation, but here is how
I have dealt with this.

insert into names (name, created_date) values ($1, default);
update names n set created_date = coalesce($2, n.craeted_date) where name
= $1;

So basically insert all of your non-defaulted columns with the primary
key. This will put the defaults into the table. Then update with
coalesce the values passed into the proc. The coalesce will use the
parameter unless it is NULL. If it is NULL it will use the default from
the table. This is inefficient since it will version the row in the table
for each call to the proc.

Brent DeSpain

Browse pgsql-general by date

  From Date Subject
Next Message Dave Huber 2009-09-29 14:31:58 Re: bulk inserts
Previous Message Andy Colson 2009-09-29 14:07:26 Re: query is taking longer time after a while