From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
---|---|
To: | Dominique Devienne <ddevienne(at)gmail(dot)com>, Francisco Olarte <folarte(at)peoplecall(dot)com> |
Cc: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Sebastien Flaesch <sebastien(dot)flaesch(at)4js(dot)com>, Kirk Wolak <wolakk(at)gmail(dot)com>, Geoff Winkless <pgsqladmin(at)geoff(dot)dj>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Using CTID system column as a "temporary" primary key |
Date: | 2023-03-30 15:13:53 |
Message-ID: | 9e27adafdc683c21b493b6fece4e50124307668f.camel@cybertec.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2023-03-30 at 14:32 +0200, Dominique Devienne wrote:
> I fail to see that myself, sorry. You can bind NULL, you can bind values, so why
> wouldn't you be able to bind DEFAULT too? I see that more as a failing to the
> binding API myself :)
That doesn't work because DEFAULT is not a value like NULL, it is
a keyword.
> But I guess it can be worked around with something like
> `... values(coalesce($1, default), ..)`
> and abusing NULL to mean DEFAULT on a case-by-case bases.
> Assuming default can be used in this way (didn't try), of course.
That won't work either, because DEFAULT is a keyword and cannot used
in expressions.
For what you want, I can think of two approaches:
1. Use two prepared INSERT statements with different column lists,
one with the column in question and the other without.
Then use the appropriate statement, depending on whether you
want the default value or not.
2. Don't use a default value, but a BEFORE INSERT trigger.
If you insert some magical value like -1, the trigger replaces
the value with some default.
The second solution is somewhat uglier (personal hudgement) and slower.
Yours,
Laurenz Albe
From | Date | Subject | |
---|---|---|---|
Next Message | Dominique Devienne | 2023-03-30 15:40:04 | libpq: COPY FROM STDIN BINARY of arrays |
Previous Message | Dominique Devienne | 2023-03-30 12:32:57 | Re: Using CTID system column as a "temporary" primary key |