The Postgres database I manage contains many columns containing numbers between 0 and 100, with a fixed (never more than 3, usually 2) number of decimal places. Most of these numbers cluster around their respective averages, and thus repeat a lot, which if implemented correctly, could make them ideal types for GIN and GIST indexing. This ties in really well with our future development plans, since GIN and/or GIST would be necessary to index certain types of queries we're planning to implement in the future. The functionality that comes with ranges would also be useful, which also would become available if they were stored as integers.
Currently, they're stored as floats, but this has caused problems in the past, when trying to look up numbers by their exact value. I'm aware of the NUMERIC class in Postgres, but that seems to do the opposite of what I want, as far as performance. We would almost never do any math with these numbers within Postgres, and for any math we did do, it would be extremely basic and precision wouldn't be important. As such, these columns seem like ideal candidates for fixed-point number types. Basically, I want to make them stored as integers internally, but when returned in queries and when set via UPDATE and INSERT, it should move the decimal point, say, three places to the left.
From my reading so far, I think I have two options. I could create triggers on those columns to manipulate the input and output of values of what would internally be integer types, or I could create custom scalar types in C. The second option seems to be the better one, but I'd think that if it were that easy to do, someone would have already done it by now. Or maybe there's a better solution that I just haven't come across yet? I'm leaning towards creating a custom data type, but I'm still not sure if there's a good reason not to.
Oh, also virtually all of the queries on these data types would be whether they fell within a given range. Possibly some addition and subtraction, but very little multiplication or division, and probably never anything more advanced than that. The code would only run one production server, possibly a test server, and 4-5 development machines. I'm not sure how much of that is relevant, but I'm hoping someone can set me on the right track.