Script for postgres database

0

I created this script, to clear the table from the bank and to clear id 's.

It works, but not the right way

It runs and authenticates on psql . but instead of running the sql command it only opens psql .

If someone has an exit already thank you.

@echo off

set PGUSER=####
set PGPASSWORD=#####

echo on

"D:\Programas\PostgreSQL\bin\psql.exe" -h localhost -p 5432 -U postgres pauliceia delete from bairros;
"D:\Programas\PostgreSQL\bin\psql.exe" -h localhost -p 5432 -U postgres pauliceia alter table bairros AUTO_INCREMENT = 1;
    
asked by anonymous 13.06.2018 / 22:12

1 answer

1

To make psql execute SQL you need to use the -c parameter and enter the string with the command (s).

link

Changing your example code would look like the example below:

@echo off

set PGUSER=#### set PGPASSWORD=#####

echo on

"D:\Programas\PostgreSQL\bin\psql.exe" -h localhost -p 5432 -U postgres -c 'delete from bairros;' -c 'alter table bairros AUTO_INCREMENT = 1;' pauliceia
    
14.06.2018 / 14:51