Обсуждение: BUG #19019: Feature Request: allow the use of column reference in DEFAULT expression

Поиск
Список
Период
Сортировка

BUG #19019: Feature Request: allow the use of column reference in DEFAULT expression

От
PG Bug reporting form
Дата:
The following bug has been logged on the website:

Bug reference:      19019
Logged by:          Paolo Saggese
Email address:      spam@bit.bucket
PostgreSQL version: Unsupported/Unknown
Operating system:   Any
Description:

As it is possible in some other SQL RDBMS, it would be useful to allow the
use of column reference in DEFAULT expression.

That is, for example:

CREATE TABLE my_table
(
    my_column my_type NOT NULL DEFAULT (  my_expression ),
    -- some other columns, constraints, etc...
)

where "my_expression" uses values from some other column(s) of (the same row
of) the same table and may be allow (also) for even more generic references
to any other column of any table in the DB (in which case "my_expression"
would be a query returning a single value compatible with "my_type"...).

A possible equivalent alternative syntax would be e.g.:

GENERATED BY DEFAULT AS ( my_expression )

(where "STORED" would be obviously implied...).

Note that the (existing) syntax:

GENERATED ALWAYS AS ( my_expression ) STORED

obviously is not equivalent and does not provide the desired behavior (as of
course in such case the column would be read-only and would not allow to
replace the generated value with something else).


Re: BUG #19019: Feature Request: allow the use of column reference in DEFAULT expression

От
"David G. Johnston"
Дата:
On Wednesday, August 13, 2025, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      19019
Logged by:          Paolo Saggese
Email address:      spam@bit.bucket
PostgreSQL version: Unsupported/Unknown
Operating system:   Any
Description:       

As it is possible in some other SQL RDBMS, it would be useful to allow the
use of column reference in DEFAULT expression.

Our bug reporting system is not an appropriate channel to submit feature requests.  Send patches to -hackers or pleas to -general.

David J.

Re: BUG #19019: Feature Request: allow the use of column reference in DEFAULT expression

От
Laurenz Albe
Дата:
On Wed, 2025-08-13 at 11:36 +0000, PG Bug reporting form wrote:
> As it is possible in some other SQL RDBMS, it would be useful to allow the
> use of column reference in DEFAULT expression.

You can use a BEFORE INSERT trigger for that.

If you allow columns in a DEFAULT expression, would that use the column value
from before or after the BEFORE triggers run?

Yours,
Laurenz Albe