17

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?
user3171954
  • 181
  • 1
  • 1
  • 4

3 Answers3

30

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
Damien Carol
  • 1,164
  • 1
  • 11
  • 21
15

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.

Paul Rigor
  • 986
  • 1
  • 12
  • 23
  • How do you enter the password ? If I put --password as an argument, it just waits forever for user input – d-_-b Apr 06 '21 at 00:16
  • 1
    @d-_-b you can set TRINO_PASSWORD envt variable to avoid password prompt. refer https://trino.io/docs/current/installation/cli.html?highlight=csv#authentication – Amith Jan 04 '22 at 05:26
0

Please see the answer on the mailing list: https://groups.google.com/forum/#!topic/presto-users/kR-3YZAaNg8

David Phillips
  • 10,723
  • 6
  • 41
  • 54