Reputation: 1072
I want to create a column in a table in postgres for special needs, this column must consist for example of a concatenation of two another column.
for example i have
LAYER: 'accessory'
TYPE: 'copper'
I want a column (symbology) to be filled automatically during an insertion or an update by
SYMBOLOGY: 'accessory - copper'
do I need a trigger to do this or is there some other ways to avoid the trigger.
Illustration
LAYER | TYPE | SYMBOLOGY |
---|---|---|
accessory | copper | accessory - copper |
cordially
Upvotes: 1
Views: 129
Reputation: 164679
You can use a generated column.
alter table things
add column symbology text
generated always as (layer || ' - ' || type)
stored;
Or, if its only for some specific circumstances, you can create a view
create view thing_symbols as
select
*,
(layer || ' - ' || type) as symbology
from things;
Upvotes: 1