Execute Query to a File

Executing to a File

Use our editor commands to spool the results of your SQL statements to .csv files. You can change the delimiter, but all files will have a .csv extension by default.

To utilize this functionality, do the following:

  • Use the #+sql command to tell the editor you will be writing SQL in this section
  • Then use the output file command to tell the editor you will spool the results to a file
  • Use a series of parameters and descriptions for spooling from the table below
  • Use the #+begin statement to tell the editor that from here until the #+end command you'll be executing this SQL
  • Write your SQL
  • End the code with #+end
  • Use the Run commands as you would for any regular SQL statement

Here is an example of how you can execute SQL to a file:

1 -- This will write the SQL statement between #+begin and #+end to the file specified.

2 #+sql
3 :output file
4 :path '/users/jschlitt/Downloads/jeff1'
5 :delimiter ','
6 :null_value 'NULL'
7 :quote_char '"'
8 :overwrite true
9 #+begin
10 select * from wb_pro_marketing_list
11 where emaildomain = 'aginity.com'
12 #+end

The currently accepted parameters in the Execute to a File commands are the following:




On Mac, it should be in the format "/dir/dir/filename." On Windows, the format will be "drive:directoryfilename."


You can use any value, but we recommend | or ^, or t for (tab)


Enter character field for null—typically ‘’ (empty string) or 'NULL'


Enter how to enclose character string—typically the quotation (")


Whether or not to allow overwriting if a file already exists: true or false


True or false on whether you want to display headers in a file


The UTF_8 file encoding is the only value supported for now


We can compress a file after it's written—values are NONE, ZIP, and GZIP


🔎 TIP: Check our knowledge base article on how to navigate the catalogs
and export to a file via CoginitiScript.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request