Postgres 17 domains with NOT NULL and pg_get_constraintdef() - Mailing list pgsql-general

From shammat@gmx.net
Subject Postgres 17 domains with NOT NULL and pg_get_constraintdef()
Date
Msg-id f90c6099-521e-48d7-99eb-07e85f606be4@gmx.net
Whole thread Raw
Responses Re: Postgres 17 domains with NOT NULL and pg_get_constraintdef()
List pgsql-general
Hello,

I am not sure if this is intended behavior or an oversight/bug.

Assume the following domain definition:

    CREATE DOMAIN sample_domain AS numeric(12,2) NOT NULL constraint positive_value CHECK (value > 0);

Up until Postgres 16 it was possible to retrieve the domain constraints using:

    select t.typname,
           pg_catalog.pg_get_constraintdef(ci.oid, true)
    from pg_catalog.pg_type t
      join pg_catalog.pg_constraint ci on ci.contypid = t.oid
    where t.typtype = 'd'
      and t.typname = 'sample_domain'

However, because the domain is defined with NOT NULL, this fails with

> ERROR: invalid constraint type "n"

with 17.2 on Windows and Linux.

This is a result of storing the NOT NULL constraint in pg_constraint
and can easily be avoided by either using contype <> 'n' or by not calling
pg_get_constraintdef if contype = 'n'

Is this a bug/oversight in pg_get_constraintdef() or does it just not support NOT NULL
constraints? The manual does not show any restriction on the usage.






pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Postgres do not support tinyint?
Next
From: Alvaro Herrera
Date:
Subject: Re: Postgres 17 domains with NOT NULL and pg_get_constraintdef()