You need to provide the data type for the column as @Belayer commented.
And then you need to explicitly cast domain_name
as text
(or some varchar
). Otherwise you'll get an error that the expression isn't immutable as @nbk commented. serial
is translated to be basically an integer
and for whatever reason implicit casts of an integer
in concatenations are considered not immutable by the engine. We had that just recently here.
So overall, using the given types for the columns, you want something like:
CREATE TABLE public.some_data
(user_name varchar NULL,
domain_name serial NOT NULL,
email text GENERATED ALWAYS AS (user_name || '@' || domain_name::text) STORED);
But it's a little weird that a domain name is a serial
? Shouldn't that be a text
or similar? Then you wouldn't need the cast of course.