Index on an input value without saving it to a column? Short version:

I'm looking for a way to give Postgres a value just for an index (as opposed to saving that value to a column and then indexing it). Similar to an index on an expression, but the expression will be computed outside of Postgres. If this is possible, how can it be done?

Long version:

I've created an index on a plpgsql function that normalizes an email address, however using it is proving to be very clunky - either I have to remember to always call the function whenever I use the index, or I have to create a view and remember to use that for reads but not for writes... On top of that, the plpgsql implementation is 3x slower than the python implementation (and 30x uglier imo), and RDS doesn't support plpythonu. So I might as well go back to go back to doing it in the application, but I don't want to go back to saving a computed column and indexing on that; I still want to have the normalized email only in the index.

The way to do this I guess would be to somehow create a fake column name, and the input for this fake column would be used for the index. If this is possible, how can it be done?
Postgres supports indexes on expressions so if the value you want to index can be computed from other values in the row this will work (assuming the queries you are using a written in a way that the query planner can see the use for the index). See https://www.postgresql.org/docs/10/static/indexes-expressional.html

For more complex requirements a materialised view might be required, though these appear to need "manual" updates via REFRESH MATERIALIZED VIEW which might make them imprctical depending on your need.



From your later edit:


  or I have to create a view and remember to use that for reads but not for writes


You can use "INSTEAD OF" triggers to make views like this appear to be directly writable, though of course you need to be careful of performance issues if the data is written to often.