postgres output to bash variable 1

postgres output to bash variable

vartest=`psql -X -A -d $dbname -U $username -h localhost -p 5432 -t -c "SELECT gid FROM testtable WHERE aid='1'"`

Here is what the above code is Doing:
1. It’s creating a new database called ‘testdb’
2. It’s creating a new table called ‘testtable’
3. It’s inserting a new row into the table
4. It’s selecting the gid from the table where the aid is 1
5. It’s storing the result of the query in a variable called ‘vartest’

Similar Posts