Using DEFAULT as a parameter value with PQexecPrepare()

From: "EXT-Rothermel, Peter M" <Peter(dot)M(dot)Rothermel(at)boeing(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Using DEFAULT as a parameter value with PQexecPrepare()
Date: 2012-04-06 00:37:56
Message-ID: 135FBA69693F3B46A0BE8D4FF49D2D83494A55ACD0@XCH-NW-01V.nw.nos.boeing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am currently dynamically building a SQL command in my C code like that executes SQL statement like:

INSERT INTO t (c1,c2,c3,c4,c5) VALUES ('abc', 1, DEFAULT, 9, 3);

I execute the command using PQexec() of libpq.

The application logic determines when to use the default values for several columns.
The first two columns do not default values so they must always be specified.

I was looking for a to use a prepared statement for this operation.

PREPARE myinsert AS "INSERT INTO t ( c1, c2, c3, c4, c5) VALUES ( $1, $2, $3, $4, $5);

Now I want to execute this prepared statement something like:

EXECUTE myinsert ( 'abc', 1, DEFAULT, 9, 3);

Is there any way to specify the column's default value as a parameter value?

Doesn't look like I can do this using the PQexecPrepared() function of libpq.
Doesn't look like I can do this using PQexecParams() as well.

I am using version 8.4 of PostgreSQL.

Thanks,
Pete Rothermel

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2012-04-06 02:10:54 Re: Hot synchron backup doesn't start
Previous Message Daniel Verite 2012-04-05 21:32:36 Re: BD impossible à recharger