Appendix: Starting with Stata 14, flying tables work without hacks.
Is there a way to configure Stata to work with temporary pivot tables? These tables and data are deleted after leaving the user session.
Here is an example of a simple toy SQL query that I use in Stata and Teradata:
odbc load, exec(" BEGIN TRANSACTION; CREATE VOLATILE MULTISET TABLE vol_tab AS ( SELECT TOP 10 user_id FROM dw_users ) WITH DATA PRIMARY INDEX(user_id) ON COMMIT PRESERVE ROWS; SELECT * FROM vol_tab; END TRANSACTION; ") dsn("mozart");
This is the error message I get:
The ODBC driver reported the following diagnostics [Teradata][ODBC Teradata Driver][Teradata Database] Only an ET or null statement is legal after a DDL Statement. SQLSTATE=25000 r(682);
The Stata error code means:
error. ,,,,,,,,,,,, Return code 682 could not connect to odbc dsn; This usually happens due to incorrect permissions, such as an incorrect username or password. Use set debug to display the actual error message generated by the ODBC driver.
As far as I can tell, everything is fine, as I can pull out the data if I just run the query "SELECT TOP 10 ...". I installed debugging, but it did not give any additional information.
Session Mode - Teradata. ODBC Manager is installed in unixODBC. I am using Stata 13.1 on an Ubuntu server.
I believe that the main problem may be that separate connections are established for each SQL statement , so the flying table evaporates by the time it is released. I am waiting for technical support to check this out.
I tried using the odbc sqlfile , but this approach does not work unless I create a persistent table at the end of it. There is no boot option with odbc sqlfile .
Flying tables seem very good in SAS and R. For example, this works fine:
library("RODBC") db <- odbcConnect("mozart") sqlQuery(db,"CREATE VOLATILE MULTISET TABLE vol_tab AS ( SELECT TOP 10 user_id FROM dw_users ) WITH DATA PRIMARY INDEX(user_id) ON COMMIT PRESERVE ROWS; ") data<- sqlQuery(db,"select * from vol_tab;",rows_at_time=1)
Perhaps this is due to the fact that the connection to the database remains open until close(db) .