I have a table test_data with 4 columns as shown below. I want to create a JSONB generated column with data from these columns. Below is what I have tried but keep on getting this error:
ERROR: generation expression is not immutable SQL state: 42P17
| name VARCHAR(50) | mixed_stuff JSONB | other_stuff JSONB | created TIMESTAMP | combined JSONB |
|---|---|---|---|---|
CREATE TABLE test_data(name VARCHAR(50), mixed_stuff JSONB, other_stuff JSONB, created TIMESTAMP WITHOUT TIMEZONE default(now() at time zone 'utc'));
ALTER TABLE test_data
add combined JSONB GENERATED ALWAYS AS (jsonb_build_object('name',name) || "mixed_stuff" || "other_stuff" || jsonb_build_object('created',created)) STORED;