Is there a sane way of storing int, float and boolean values in the same column in Postgres?
If have something like that:
| rid | time | value |
|---|---|---|
| 2d9c5bdc-dfc5-4ce5-888f-59d06b5065d0 | 2021-01-01 00:00:10.000000 +00:00 | true |
| 039264ad-af42-43a0-806b-294c878827fe | 2020-01-03 10:00:00.000000 +00:00 | 2 |
| b3b1f808-d3c3-4b6a-8fe6-c9f5af61d517 | 2021-01-01 00:00:10.000000 +00:00 | 43.2 |
Currently I'm using jsonb to store it, the problem however now is, that I can't filter in the table with for instance the greater operator.
The query
SELECT *
FROM points
WHERE value > 0;
gives back the error:
ERROR: operator does not exist: jsonb > integer: No operator matches the given name and argument types. You might need to add explicit type casts.
For me it's okay to handle boolean as 1 or 0 in case of true or false. Is there any possibility to achieve that with jsonb or is there maybe another super type which lets me use a column that is able to use all three types?
Performance is not so much of a concern here, as I'm going to have very few records inside of that table, max 5k I guess.
>, how is that supposed to work withtrue? Is this really one field or two or even three?valuethere is not really much that can be done in way of an answer. Also there is no explanation as to why you want to mix types in a column? To me that is a sign of poor design.