Create an index on the result of a custom function (written in a procedural language that is part of the DBMS).
create table products ( id integer not null primary key, code varchar(100) not null ); create function get_number(p_value text) returns integer as $$ begin return cast(regexp_replace(p_value, '[^0-9]', '', 'g') as integer); end; $$ immutable language plpgsql; create index ix_code_number on products( get_number(code) );
This index would be used by statements like this:
select * from products where get_number(code) = 42;