Execute SQL command in the terminal

Asked

Viewed 1,769 times

0

I’m wanting to run sql command through the Windows prompt but I don’t know what the initial settings to do this. Can anyone tell me?

Detail: It has to be in the windows terminal.

  • 1

    What settings? Software requests/tutorials are outside the scope of the site. I recommend reading the [tour] and [Ask]. Tried to register the postgres executable (via command line) in the windows PATH (environment variable) ?

  • I suggest changing the title: How to execute SQL command in the terminal?

  • Have any answers solved what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?

2 answers

2


Use the tool psql, present in the Postgresql installation.

To log in, type:

psql -U usuarioDoBanco nomeDeUmBanco

Then you can execute commands such as:

select datname, oid from pg_database;

Command image for terminal connection: inserir a descrição da imagem aqui

  • has to be at the terminal !!

  • 1

    Yes, psql is in the terminal!

  • Thank you very much ,got it

0

follows an example without having to log in

psql --command="select codigo from produto where codigo = 'codigo_do_produto'" --host=localhost --port=5432 --username=postgres --dbname=banco
  • This response was flagged as low quality due to size or content. Please, if possible and if this is a solution to the problem, explain better how you solved it. The code may be trivial to you, but to other users it may not be.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.