Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export result of select statement in prestodb.io

Tags:

presto

Two things.

  1. How can I execute an sql statement without "presto-cli-0.56-executable.jar", for example I want to provide a web interface where people could write query and see the output on web
  2. How to export the result of the select statement into a file?
like image 895
user3171954 Avatar asked Jan 08 '14 06:01

user3171954


People also ask

How do I write a Presto CTE query?

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.

How do I redirect the output of Presto to a file?

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:

What is Presto SQL?

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.

What's new in PrestoDB?

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.


2 Answers

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
like image 137
Damien Carol Avatar answered Sep 18 '22 13:09

Damien Carol


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.

like image 33
Paul Rigor Avatar answered Sep 18 '22 13:09

Paul Rigor