ECPG: inserting NULL values when using prepared statements

From: Anders Nilsson <Anders(dot)Nilsson(at)noaa(dot)gov>
To: pgsql-general(at)postgresql(dot)org
Subject: ECPG: inserting NULL values when using prepared statements
Date: 2007-04-02 16:53:50
Message-ID: 4611351E.4040605@noaa.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The situation:
A loop that inserts thousands of values into a table.
In hopes of optimizing the bunches of inserts, I prepared
a statement like the follows:

"insert into some_table_name ( value, id, date ) values ( ?, ?, ? )"

then executing the prepared statement identifier numerous times
using already declared host variables.

The problem:
Some of these values are null. Is there a way to specify a null
value without having to rewrite the statement with the explicit NULL
replacing the "?" ?
The section on indicator values (30.6.4 in the 8.1.3 help) does
mention:

"To be able to pass null values to the database or retrieve null
values from the database, you need to append a second host variable
specification to each host variable that contains data."

(If this works) if I were to use indicator variables when
inserting, what would the syntax be? So far, indicator variables work
great when fetching, though I just can't seem to get it right when
inserting / updating. Or, if there is another method to specify NULL
values, that would be great as well.

Any help would be appreciated.

Thanks,
-Anders Nilsson

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thorsten Kraus 2007-04-02 17:27:59 Webappication and PostgreSQL login roles
Previous Message Tom Lane 2007-04-02 16:17:43 Re: Unexplained case insensitive results