From: Volkan YAZICI <yazicivo@ttnet.net.tr>
To: JiangWei <jw.pgsql@sduept.com>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: HOWTO pass "default value" to PQexecParams?
Date: Sat, 7 Jan 2006 11:44:56 +0200
Message-ID: <20060107094455.GA634@alamut> (raw)
In-Reply-To: <43BDC4EF.7090408@sduept.com>
References: <43BDC4EF.7090408@sduept.com>
AFAIK, it's not possible to point the field's default value using a
special value in the related array member. Because, you cannot declare
any special value in the array: NULL will be treated as NULL and other
char values as is.
(Recommended.) Why don't you omit id in the target table fields?
For instance:
sprintf(sql_cmd, "INSERT INTO test ("
(id_will_be_default) ? "" : "id, "
"name) VALUES ("
"...");
PQexecParams(conn, sql_cmd, ...);
You can also learn the default value of the related field too. (For
more information, run psql with -E parameter and type \d <table>.)
Furthermore, it's possible to define a RULE like:
ON INSERT
IF NEW.id = 0
USE DEFAULT
This will assume 0 as a reference to default value.
HTH.
Regards.
On Jan 06 09:16, JiangWei wrote:
> Create Table test (
> id int4 not null,
> name text default '<noname>'
> );
>
> PQexec (conn, "INSERT INTO test(id, name) VALUES (100,default)" ); // OK.
>
> PQexecParams (conn, "INSERT INTO test(id, name) VALUES ($1, $2)" ); //
> $1=100, $2= ????
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: yazicivo@ttnet.net.tr, jw.pgsql@sduept.com
Subject: Re: HOWTO pass "default value" to PQexecParams?
In-Reply-To: <20060107094455.GA634@alamut>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox