pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedHOWTO pass "default value" to PQexecParams ?
5+ messages / 2 participants
[nested] [flat]
* HOWTO pass "default value" to PQexecParams ?
@ 2006-01-06 01:16 JiangWei <jw.pgsql@sduept.com>
0 siblings, 1 reply; 5+ messages in thread
From: JiangWei @ 2006-01-06 01:16 UTC (permalink / raw)
To: pgsql-interfaces
-- SQL Script
Create Table test (
id int4 not null,
name text default '<noname>'
);
-- C
PQexec (conn, "INSERT INTO test(id, name) VALUES (100,default)" ); // OK.
PQexecParams (conn, "INSERT INTO test(id, name) VALUES ($1, $2)" ); //
$1=100, $2= ????
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: HOWTO pass "default value" to PQexecParams?
@ 2006-01-07 09:44 Volkan YAZICI <yazicivo@ttnet.net.tr>
parent: JiangWei <jw.pgsql@sduept.com>
0 siblings, 1 reply; 5+ messages in thread
From: Volkan YAZICI @ 2006-01-07 09:44 UTC (permalink / raw)
To: JiangWei <jw.pgsql@sduept.com>; +Cc: 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:
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= ????
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: HOWTO pass "default value" to PQexecParams?
@ 2006-01-09 08:18 JiangWei <jw.pgsql@sduept.com>
parent: Volkan YAZICI <yazicivo@ttnet.net.tr>
0 siblings, 1 reply; 5+ messages in thread
From: JiangWei @ 2006-01-09 08:18 UTC (permalink / raw)
To: Volkan YAZICI <yazicivo@ttnet.net.tr>; +Cc: pgsql-interfaces
Volkan YAZICI wrote:
>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.
>
>
We can declare a specialized oid for this.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: HOWTO pass "default value" to PQexecParams?
@ 2006-01-09 10:41 Volkan YAZICI <yazicivo@ttnet.net.tr>
parent: JiangWei <jw.pgsql@sduept.com>
0 siblings, 1 reply; 5+ messages in thread
From: Volkan YAZICI @ 2006-01-09 10:41 UTC (permalink / raw)
To: JiangWei <jw.pgsql@sduept.com>; +Cc: pgsql-interfaces
On Jan 09 04:18, JiangWei wrote:
> >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.
>
> We can declare a specialized oid for this.
You mean in the parameter types? If so, is this supported by PostgreSQL?
Regards.
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: HOWTO pass "default value" to PQexecParams?
@ 2006-01-10 00:48 JiangWei <jw.pgsql@sduept.com>
parent: Volkan YAZICI <yazicivo@ttnet.net.tr>
0 siblings, 0 replies; 5+ messages in thread
From: JiangWei @ 2006-01-10 00:48 UTC (permalink / raw)
To: Volkan YAZICI <yazicivo@ttnet.net.tr>; +Cc: pgsql-interfaces
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Volkan YAZICI wrote:
<blockquote cite="mid20060109104145.GA546@alamut" type="cite">
<pre wrap="">On Jan 09 04:18, JiangWei wrote:
</pre>
<blockquote type="cite">
<blockquote type="cite">
<pre wrap="">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.
</pre>
</blockquote>
<pre wrap="">We can declare a specialized oid for this.
</pre>
</blockquote>
<pre wrap=""><!---->
You mean in the parameter types? </pre>
</blockquote>
Yes.<br>
<blockquote cite="mid20060109104145.GA546@alamut" type="cite">
<pre wrap="">If so, is this supported by PostgreSQL?
</pre>
</blockquote>
No. Just an idea. "EXPRESSION_OID" for 'DEFAULT' , ' foo ( id, 2) ',
'm * n + x' ...<br>
<br>
<br>
</body>
</html>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2006-01-10 00:48 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-01-06 01:16 HOWTO pass "default value" to PQexecParams ? JiangWei <jw.pgsql@sduept.com>
2006-01-07 09:44 ` Re: HOWTO pass "default value" to PQexecParams? Volkan YAZICI <yazicivo@ttnet.net.tr>
2006-01-09 08:18 ` Re: HOWTO pass "default value" to PQexecParams? JiangWei <jw.pgsql@sduept.com>
2006-01-09 10:41 ` Re: HOWTO pass "default value" to PQexecParams? Volkan YAZICI <yazicivo@ttnet.net.tr>
2006-01-10 00:48 ` Re: HOWTO pass "default value" to PQexecParams? JiangWei <jw.pgsql@sduept.com>
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