How to execute multiple statements in presto?

by aniya.jaskolski , in category: Third Party Scripts , 9 days ago

How to execute multiple statements in presto?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 8 days ago

@aniya.jaskolski 

In Presto, you can execute multiple statements by separating them with a semicolon (;) as shown below:

1
2
3
4
5
-- Query 1
SELECT column1 FROM table1;

-- Query 2
SELECT column2 FROM table2;


You can also use the DO command to execute multiple statements as a single transaction, like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
DO
$$
DECLARE
    variable1 INT := 1;
    variable2 INT := 2;
BEGIN
    SELECT variable1;
    SELECT variable2;
END
$$


Remember to end each statement with a semicolon (;) when using the DO command.