Skip site navigation (1) Skip section navigation (2)

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

From: Richard Huxton <dev(at)archonet(dot)com>
To: Postgres User <postgres(dot)developer(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Using Insert - Default in a condition expression ??
Date: 2009-09-29 08:34:19
Message-ID: 4AC1C68B.4030407@archonet.com (view raw or flat)
Thread:
Lists: pgsql-general
Postgres User wrote:
>>> I'm trying to write an INSERT INTO statement that will use a DEFAULT
>>> value when an input parameter is null.
>>>
>> Neither of my 2 methods are pretty.
>> 1) Use a trigger.
>> 2) Grab and cast the default value from the information_schema.columns
>> view and plug it in.
>>
>> Another option is to build your insert sql as a string and then execute it.
>>
> 
> Thanks... those approaches came to mind.  But I need something more
> flexible as the Insert functions are generated by an ORM layer.  It
> has to be simpler.

You're not going to get anything simpler than building a string and
calling execute. Nor more flexible, come to think of it.

BTW - surely the ORM should be generating your defaults for you?

-- 
  Richard Huxton
  Archonet Ltd

In response to

pgsql-general by date

Next:From: Paul GasparDate: 2009-09-29 08:52:02
Subject: Collation in ORDER BY not lexicographical
Previous:From: Gy├Ârgy VilmosDate: 2009-09-29 07:36:37
Subject: Performance evaluation of PostgreSQL's historic releases

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group