2021-09-30

How to Run PostgreSQL Query Using Bash Script and Command-Line

#!/bin/bash
#/opt/script/postgres-query-from-shell.sh
#LastUpdate: #11:54 2021.08.02
#----------------------------------------
#su - postgres -c 'psql -h 127.0.0.1'
#su -c "psql -d database_name -c \"SELECT c_defaults  FROM user_info WHERE c_uid = 'testuser'\"" postgres
su - postgres -c "psql -h 127.0.0.1 -d dvdrental -c 'select film_id,title,description from film order by film_id asc limit 5'"



#!/bin/bash
#/opt/script/postgres-query-from-shell-update-load-test.sh
#LastUpdate: #14:13 2021.08.02
#----------------------------------------
#su - postgres -c "psql -h 127.0.0.1 -d dvdrental -c 'select film_id,title,description from film order by film_id asc limit 5'"
#update film set title='Ace Goldfinger-201' where film_id=2
for var_temp in {1..1000}
do
   echo "[DATE: $(date +'%H:%M:%S_%6N')]--------------VALUE: $var_temp"
   su - postgres -c "psql -h 127.0.0.1 -d dvdrental -c \"update film set title='Ace Goldfinger-$var_temp' where film_id=2\""
done




#REF:
for var01 in {1..1000}
do
   echo "Welcome $var01 times"
done

DO
$do$
BEGIN 
    FOR i IN 1..25 LOOP
        -- COMMAND
    END LOOP;
END
$do$;

No comments:

Post a Comment