Dear list,
I ran into an error when running the following snippet of code (I simplified as much as I could):
CREATE DOMAIN domaintest AS VARCHAR(10) NOT NULL;
CREATE TABLE tabletest (
fieldtest domaintest GENERATED ALWAYS AS ('valuetest') STORED
);
INSERT INTO tabletest DEFAULT VALUES;
In PostgreSQL 12 and 13, I get the following error:
domain domaintest does not allow null values.
If I move the NOT NULL constraint from the domain to the table, the error disappears.
I suspect that the NULL check is done before the GENERATED column is actually computed. I don't think this is related to the warning the documentation gives about NULL values and DOMAINs (https://www.postgresql.org/docs/13/sql-createdomain.html#id-1.9.3.62.7).
Thank you,
--
Fabian Pijcke