I have several type columns in my database schema.
For example there is a type_id
column which can either be the primary, secondary, work or old address.
Querying for all old addresses of an employee would look like this:
select a.*
from employees e
join employeeaddresses ea on ea.employee_id = e.employee_id
join addresses a on ea.adress_id = a.address_id
where ea.type_id = 4 -- old addresses
I would like to introduce a database wide constant TYPE_OLDADDRESS
that is internally mapped to 4.
So the query would look like this:
select a.*
from employees e
join employeeaddresses ea on ea.employee_id = e.employee_id
join addresses a on ea.adress_id = a.address_id
where ea.type_id = TYPE_OLDADDRESS;
Is postgres capable of this or is there a workaround for this?