Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux