I was wondering if there is a reliable way to instrument SQL query statements such as
SELECT * from table where 1=1;
into a new statement like the follows that stores the result relation into a temporary table.
SELECT * into temp result from table where 1=1;
For this simple statement, I can parse the statement and add into
clause before from
. I was just wondering if there are some libraries that can do this for complicated statements with WITH
etc, so that the end result of a set of query statements is stored into a result
table.
BTW, I am using PHP/JavaScript with PostgresSQL 9.3.
Thanks.
Clarification:
This question is not a duplicate of Creating temporary tables in SQL or Creating temporary tables in SQL, because those two questions are about SQL grammar/usage issues around creating temporary tables. This question is not about SQL usage but about program instrumentation and whether/how a sequence of SQL query statements can be analyzed and transformed to achieve certain effects. So it's not about how to manually write new statements from scratch, but rather about how to transform an existing set of statements.