Generated columns in PostgreSQL 12
Here’s a new feature coming in Postgres 12:The ability to have a non-updatable column that is generated by a function.CREATE OR REPLACE FUNCTION my_concat(text, VARIADIC text[]) RETURNS TEXT AS 'text_concat_ws' LANGUAGE internal immutable; CREATE TABLE addresses ( id bigserial primary key, address1 text, address2 text, address3 text, city text, state text, zip text, delivery_address text generated always as (my_concat(E'\n',address1,address2,address3,my_concat(' ',my_concat(',', city, state),zip)) ) stored ); INSERT INTO addresses (address1,address3,city,state, zip) VALUES ('105 Live Oak Street','c/o Somebody, Somewhere','Live Oak Village','TX','78039'); SELECT delivery_address FROM addresses;
source:
$link[host]
Read Original Source