Re: How to insert default value with libpq?

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: sanpi+postgersql(at)homecomputing(dot)fr, pgsql-interfaces(at)lists(dot)postgresql(dot)org
Subject: Re: How to insert default value with libpq?
Date: 2020-04-28 14:25:48
Message-ID: 4aad674b-64c1-61d4-42f1-0adb292ee989@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

On 2020-04-27 15:02, sanpi+postgersql(at)homecomputing(dot)fr 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

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Greg Sabino Mullane 2020-04-28 15:36:06 DBD::Pg version 3.11.1 released
Previous Message sanpi+postgersql 2020-04-27 13:02:38 How to insert default value with libpq?