The GENERATED clauses below all fail to compile in psql, w/ ERROR 42601
What is the correct syntax ? (or are GENERATED NUMRANGEs not supported ?)
CREATE TABLE lh (
l NUMERIC,
h NUMERIC,
--lhr NUMRANGE GENERATED ALWAYS AS numrange(l,h) STORED
--lhr NUMRANGE GENERATED ALWAYS AS (l,h)::NUMRANGE STORED
--lhr NUMRANGE GENERATED ALWAYS AS '(l,h)'::NUMRANGE STORED
--lhr NUMRANGE GENERATED ALWAYS AS (l::NUMERIC,h:NUMERIC) STORED
lhr NUMRANGE GENERATED ALWAYS AS (l::NUMERIC,h:NUMERIC)::NUMRANGE STORED
);
CodePudding user response:
You can:
CREATE TABLE lh (
l NUMERIC,
h NUMERIC,
lhr NUMRANGE GENERATED ALWAYS AS (numrange(l,h)) STORED
);
You need to include the expression in ()
.
Not sure why you would as it just duplicates existing data that could be just as easily included in query as numrange(l,h) AS lhr
.