To clarify other correct answers, I use temporary tables mainly for performance problems, for example, when I have a parameterized subset of data that should be a query for a larger set, for example:
select * from MAIN_TABLE where MAIN_TABLE.ID in (select ID from GTT$IDS)
where GTT $ IDS is populated with a subset of identifiers.
Sometimes, for very complex procedures, I have to use several temporary tables, so I create them in the metadata (outside the PSQL instructions, of course) as follows:
create global temporary table GTT$IDS_1 (INT1 integer, INT2 integer); create index IDX_GTT$IDS_11 on GTT$IDS_1 (INT1); create index IDX_GTT$IDS_12 on GTT$IDS_1 (INT2); create global temporary table GTT$IDS_2 ... create global temporary table GTT$IDS_3 ...
Doing this may be simplified for some advanced SQL developers, but it makes the most sense to me (moving the technique from my dBase / VFP days), and it is very fast compared to a bunch of complex joins.
I really did not find the time to learn how to use the PLAN clause (or make it work correctly), so basically I use this method to create a PLAN through the code when I get slow queries, if that makes sense.
source share