DISCLAIMER: This question is similar to the stack overflow question here, but none of those answers work for my problem, as I will explain later.
I\'m t
Apparently you want to "rebuild" a table. If you only want to rebuild a table, not copy it, then you should use CLUSTER instead.
SELECT count(*) FROM table; -- make a seq scan to make sure the table is at least
-- decently cached
CLUSTER someindex ON table;
You get to choose the index, try to pick one that suits your queries. You can always use the primary key if no other index is suitable.
If your table is too large to be cached, CLUSTER can be slow though.