Execute SQL command in terminal

0

I'm trying to run sql command through the windows prompt but I do not know the initial settings to do this. Can anyone tell me?

Detail: It must be in the windows terminal.

    
asked by anonymous 16.02.2017 / 14:16

2 answers

2

Use the psql tool in the PostgreSQL installation.

To login, type:

psql -U usuarioDoBanco nomeDeUmBanco

Then you can execute commands, such as:

select datname, oid from pg_database;

Command image for connection to terminal:

    
16.02.2017 / 14:20
0

follow an example without logging in

psql --command="select codigo from produto where codigo = 'codigo_do_produto'" --host=localhost --port=5432 --username=postgres --dbname=banco
    
03.06.2017 / 00:41