My database looks like below:
- id
- message
I can list the rows with a query like this:
SELECT * FROM my_table
However, I want to list them nested, like below:
my_name
my_message
another_name
another_message
new_name
new_message
some_name
some_message
With normal ids it would look like below:
1
3
4
2
The SQL is not aware of the nesting. I could use a parent_id
which is quite common. However, it's quite tricky to get right with pagination etc.
An idea I have is to use float
on the ids instead. Then it would look like below:
1
1.1
1.2
2
2.1
2.2
The SQL will make the order correct without hassle and a pagination would be easy as well.
Is there any pitfalls with the float approach? I've never seen anyone use it.