SQLAnywhere: How to write result of a query into a file with non-interactive session

dba.stackexchange https://dba.stackexchange.com/questions/86282

  •  12-12-2020
  •  | 
  •  

Pergunta

I'm looking for a way to write resultset of a query to a file maybe analog of queryout of MS SQL or the COPY from PostgreSQL

When using something like

select count(*) from "table" OUTPUT TO 'results.txt' FORMAT TEXT

I'm getting

Could not execute statement. Syntax error near 'TO' on line 1 SQLCODE=-131, ODBC 3 State="42000" Line 1, column 1

When running it, as discribed in documentation like this:

select count(*) from "table";
OUTPUT TO 'results.txt' FORMAT TEXT

e.g. inside a procedure, I'm getting an error telling me that there is no result for being outputted.

Foi útil?

Solução 2

I found a solution for at least my problem. It's possible to put results into a temporary table and unload the temp table. So something like:

SELECT * INTO #tmpresultset FROM myTable
UNLOAD TABLE #tmpresultset to '/some/file'

Outras dicas

You can specify the OUTPUT to a file in your SQL directly:

dbisql -c "connection-string" SELECT * FROM table; OUTPUT TO 'results.txt' FORMAT TEXT

As per the Sybase documentation.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a dba.stackexchange
scroll top