--Now that we have the PL/pgSQL procedural language (thanks to Jan Wieck) --you can do almost every thing you desire with PostgreSQL in a easy way. --For example; to emulate COBOL level 88, as you suggest you may create --the DECODE function as in: --COBOL level 88 using views and decode function------------------------------ drop function decode(text,text,bool); create function decode(text,text,bool) returns bool as ' DECLARE stringa text; substringa text; code text; value text; i int2; z int2; BEGIN stringa:= $2; loop i:= position(''='' in stringa); if i = 0 then return $3; end if; z:= position('','' in stringa); if z = 0 then z:= textlen(stringa)+1; end if; value:= substr(stringa,i + 1,z - i - 1); code:= substr(stringa,1,i - 1); if $1 = code then return value; else if z > 0 then stringa:= substr(stringa,z + 1); else return $3; end if; end if; end loop; END; ' language 'plpgsql'; drop table customer, customer_view; create table customer( customer_id numeric, customer_name varchar(30), customer_status char(1), sales_rep numeric ); insert into customer values (1,'Pippo','A',20); insert into customer values (2,'Pluto','H',50); insert into customer values (3,'Topolino','a',10); insert into customer values (4,'Paperino','P',30); create view customer_view as select customer_id, customer_name, sales_rep, DECODE (customer_status,'A=TRUE,a=TRUE',FALSE) as active_client, DECODE (customer_status,'H=TRUE,h=TRUE',FALSE) as historical_client, DECODE (customer_status,'I=TRUE,i=TRUE',FALSE) as invalid_client, DECODE (customer_status,'P=TRUE,p=TRUE',FALSE) as potential_client, DECODE (customer_status,'A=TRUE,a=TRUE,P=TRUE,p=TRUE',FALSE) as current_client from customer; select customer_id, customer_name, active_client, sales_rep from customer_view where active_client; select customer_id, customer_name, active_client, sales_rep from customer_view where not active_client; --The other solution as you suggest is to have a function for every level 88 --this is a better choice to have high performance... --COBOL level 88 using functions----------------------------------------------- drop function current_client(text); create function current_client(text) returns bool as ' DECLARE status ALIAS for $1; BEGIN RETURN status IN (''A'',''a'',''P'',''p''); END; ' language 'plpgsql'; drop function active_client(text); create function active_client(text) returns bool as ' DECLARE status ALIAS for $1; BEGIN RETURN status IN (''A'',''a''); END; ' language 'plpgsql'; select * from customer where active_client(customer_status); select * from customer where not active_client(customer_status);