DrDroid
Resource Cheatsheet

Presto

Quick reference guide and commands for Presto.

Download PDF

Connection

Connect to Presto Server
presto --server : --catalog --schema

Connect with Authentication
presto --server : --catalog --schema --user

Connect with SSL
presto --server https://: --catalog --schema --truststore-path --truststore-password

Basic Queries

List Catalogs
SHOW CATALOGS;

List Schemas
SHOW SCHEMAS FROM ;

List Tables
SHOW TABLES FROM .;

Show Table Details
DESCRIBE ..;

Show Table Properties
SHOW CREATE TABLE ..;

Query Execution

Simple SELECT
SELECT * FROM .. LIMIT 10;

Filtered Query
SELECT * FROM .. WHERE ;

Join Query
SELECT a.*, b.* FROM a JOIN b ON a.id = b.id;

Aggregate Query
SELECT column, COUNT(*) FROM GROUP BY column;

Query Management

List Running Queries
SELECT query_id, state, user, source FROM system.runtime.queries;

Kill a Query
CALL system.runtime.kill_query(query_id => '', message => 'Terminating query');

View Query Stats
SELECT * FROM system.runtime.queries WHERE query_id = '';

Performance Analysis

View Query Plan
EXPLAIN SELECT * FROM ;

Detailed Query Plan
EXPLAIN ANALYZE SELECT * FROM ;

Check Table Statistics
SHOW STATS FOR ;

Data Manipulation

Create Table
CREATE TABLE . (id bigint, name varchar);

Create Table As
CREATE TABLE . AS SELECT * FROM .;

Insert Data
INSERT INTO . VALUES (1, 'value'), (2, 'value2');

Drop Table
DROP TABLE .;

Advanced Features

Create View
CREATE VIEW . AS SELECT * FROM . WHERE ;

Use Window Functions
SELECT id, name, ROW_NUMBER() OVER (PARTITION BY category ORDER BY value) FROM ;

Execute SQL Function
SELECT (column) FROM ;

Set Session Property
SET SESSION = '';