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

Re: HOWTO pass "default value" to PQexecParams?

From: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
To: JiangWei <jw(dot)pgsql(at)sduept(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: HOWTO pass "default value" to PQexecParams?
Date: 2006-01-07 09:44:56
Message-ID: 20060107094455.GA634@alamut (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
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:

  IF = 0

This will assume 0 as a reference to default value.


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= ????

In response to


pgsql-interfaces by date

Next:From: Ludek FinstrleDate: 2006-01-08 08:58:51
Subject: libpq and auth type
Previous:From: JiangWeiDate: 2006-01-06 04:45:36
Subject: Re: [C API] Is there a nice way to get table/column

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