How to execute multiple statement in PgAdmin 4 like we do in Sql Server/Oracle?

pgadmin

How to execute multiple statement in PgAdmin 4 like we do in Sql Server/Oracle (press F5)?

select * from employees;

select * from department;

As much I worked with PgAdmin, it allows us to execute only one selected statement or last statement per time, is there any way or any setting to execute multiple dml statement together?

Best Answer

pgAdmin (both III and 4) execute both statements. For the first one, it just discards the output, unless there is an error.

You can actually chain as many statements as you want:

-- We create one table
CREATE TABLE digit_names 
(   
    digit integer PRIMARY KEY,
    digit_name text,
    UNIQUE (digit_name)
) ;

-- Fill it with values
INSERT INTO digit_names 
VALUES
    (0, 'zero'),
    (1, 'one'),
    (2, 'two'),
    (3, 'three'),
    (4, 'four'),
    (5, 'five'),
    (6, 'six'),
    (7, 'seven'),
    (8, 'eight'),
    (9, 'nine') ;

-- And perform a SELECT query
SELECT
    digit_name 
FROM
    digit_names 
    JOIN (VALUES (1), (2), (3) ) AS three_digits(digit) USING (digit) ;

-- All in just one statement.

But you'll get only the output from the last one.

If you're using pgAdmin 4, you just type everything on the Query Tool pane, and then press the button with a [lightning bolt] (or press F5).