Two things.
Here’s a CTE example query: presto> WITH my_time_data (the_time_now) as ( select now () ) SELECT the_time_now FROM my_time_data; the_time_now --------------------------------------- 2021-01-18 12:23:12.167 Europe/London (1 row) The above Presto query example and documentation link should get you up and running writing Presto queries.
Here are two options. If you are using the Presto command line tool presto-cli (or just presto on the Mac if you used brew install presto) then use the --output-format parameter and redirect the output to a regular file. For example:
Since Presto is an ANSI SQL query engine, its SQL will be very familiar to practically anyone who has used a database, despite the fact Presto is not technically a database since it stores no data itself.
Project Aria – PrestoDB can now push down entire expressions to the data source for some file formats like ORC. Blog Design Project Presto Unlimited – Introduced exchange materialization to create temporary in-memory bucketed tables to use significantly less memory.
Simple answer :
presto --execute "select * from foo" --output-format CSV > foo.csv
You can use these formats :
ALIGNED
VERTICAL
CSV
TSV
CSV_HEADER
TSV_HEADER
For completeness, you can run the presto cli client like so
presto --server {server_name}:{server_port} --catalog {catalog_name} --schema {schema_name} --user {user_name} --execute "SELECT * FROM table_name LIMIT 1" --output-format CSV > output_fname.csv
And if you want the header to be included, use the following as hinted by answers above
--output-format CSV_HEADER
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With