I have the following SELECT statement for a PostgreSQL database to be executed from a bash script:
psql -U chh1 -d crewdb -c "SELECT SETVAL('date_link_date_linkid_seq', (SELECT MAX(date_linkid) FROM date_link), true);"This would be the desired syntax for the command to be executed in the script. I want to replace date_link with a variable that is read from STDIN. To this end I have written the following bash script:
1 #!/bin/bash 2 3 echo "Please enter the table name: " 4 read -r var 5 6 7 echo 'psql -U chh1 -d crewdb -c "SELECT SETVAL('"${var}"_"${var}id_seq"', (SELECT MAX("${var}id") FROM "$var"), true);"'When I run it the SELECT MAX(.. part is not working and I get the following output:
psql -U chh1 -d crewdb -c "SELECT SETVAL(date_link_date_linkid_seq, (SELECT MAX("${var}id") FROM "$var"), true);"Can you please help?
7 Reset to default