- 1 year ago
How to pass a variable to a psql call in a batch file?
Comment
1 / 1
To pass a variable to a psql call in a batch file, you can use the set
command to set the value of a variable, and then use that variable in your psql command.
Here is an example:
bash@echo off
set /p dbname=Enter database name:
set /p username=Enter username:
set /p password=Enter password:
psql -d %dbname% -U %username% -h localhost -p 5432 -c "SELECT * FROM users WHERE password='%password%';"
In this example, the set /p
command prompts the user to enter values for the dbname
, username
, and password
variables. These variables are then used in the psql command using %
delimiters to indicate variable substitution. Note that the password variable is enclosed in single quotes to prevent any special characters in the password from causing issues in the psql command.