views:

1204

answers:

2
+1  A: 

Is the schema fixed, or can you change it? In particular could you add another (nullable) column to store the floating point value, if any? Then a trigger for insert/update could make sure that the numeric column always has the right value. This assumes that you're going to be querying more often than inserting/updating of course.

Jon Skeet
Yeah, I thought about that. Would that be a lot of wasted space for the nulls? I was also thinking of a table with a OneToOne relation that would be populated on a trigger. There are criteria I could use on other fields to tell if a value will never be numeric.
User1
I don't know how Postgres stores nulls... you should probably read up on the exact table structure or just experiment.
Jon Skeet
Storing a numeric datatype seems to have worked. I think it's worth the extra storage. Partial indexes the most. Now my queries went from 7 minutes to 20 seconds..not bad.
User1
+1  A: 

For speed, I would go with the solution of keeping a separate column with a numeric type that is updated by a trigger. Nulls don't waste any space. Otherwise, the solution with a stored procedure (or a case expression should be enough) that checks the value and then casts it sounds right. Catching exceptions will probably be the most expensive solution of them all.

Peter Eisentraut