Script for postgres bank

Asked

Viewed 1,024 times

0

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

It works, but not in the right way

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

If anyone has a way out I’d appreciate it.

@echo off

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

echo on

"D:\Programas\PostgreSQL\10\bin\psql.exe" -h localhost -p 5432 -U postgres pauliceia delete from bairros;
"D:\Programas\PostgreSQL\10\bin\psql.exe" -h localhost -p 5432 -U postgres pauliceia alter table bairros AUTO_INCREMENT = 1;
  • the script q vc says, is a . Bat ? see syntax: https://www.postgresql.org/docs/9.2/static/app-psql.html

1 answer

1

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

https://www.postgresql.org/docs/current/static/app-psql.html

Changing your example code would be as example below:

@echo off

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

echo on

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

Browser other questions tagged

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