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";

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


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.

|improve this answer|||||
  • I'm getting a syntax error – frlan Dec 16 '14 at 14:50
  • What is the error? – LowlyDBA Dec 16 '14 at 14:51
  • I was missing a ; - try now. – LowlyDBA Dec 16 '14 at 14:56
  • This is working inside isql, but not e.g. inside non-interactive one. – frlan Dec 16 '14 at 14:57
  • Let's move this to a chat – LowlyDBA Dec 16 '14 at 15:05

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'
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.