How to insert default value with libpq?

Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to insert default value with libpq?

sanpi+postgersql
Hello,

I would like to insert the default value for a field with libpq, but
inserting null or "default" doesn’t work.

I attached a simple example also available here
https://gitlab.com/snippets/1970590

Is it possible?

main.c (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How to insert default value with libpq?

Peter Eisentraut-6
On 2020-04-27 15:02, [hidden email] wrote:
> I would like to insert the default value for a field with libpq, but
> inserting null or "default" doesn’t work.

You cannot represent that using query parameters (PQexecParams).  Query
parameters always mean, use this rather than the default value.

To do what you want either write DEFAULT or leave off the column
altogether, for example

     INSERT INTO test (id) VALUES (DEFAULT)

but this needs to be pasted into the query string, not passed as a
parameter.

--
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


Reply | Threaded
Open this post in threaded view
|

Re: How to insert default value with libpq?

sanpi+postgersql

Le 28/04/2020 à 16:25, Peter Eisentraut a écrit :
> but this needs to be pasted into the query string, not passed as a
> parameter.

Fine, thank you for your help!