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

Поиск
Список
Период
Сортировка
От brent_despain@selinc.com
Тема Re: Using Insert - Default in a condition expression ??
Дата
Msg-id OF1F917042.CC263F52-ON88257640.004DA473-87257640.004E48DF@selinc.com
обсуждение исходный текст
Ответ на Using Insert - Default in a condition expression ??  (Postgres User <postgres.developer@gmail.com>)
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Andy Colson
Дата:
Сообщение: Re: query is taking longer time after a while
Следующее
От: Dave Huber
Дата:
Сообщение: Re: bulk inserts