Ejecutar Sentecias PostgreSQL desde Código Shell
Con la ayuda del terminal interactivo psql, puedes ejecutar comandos psql usando codigo Shell. Para este propósito deberías habilitar la contraseña de logeo por medio de pg_hba.conf, o .pgpass.
PostgreSQL: Ejecutando SQL desde código Shell
Provee todos los comandos postgreSQL entre el bloque EOF
PostgreSQL: Usando Variables en SQL en un código Shell
Puedes usar variables shell dentro del bloque EOF
Sintaxis
psql BASEDEDATOS USUARIO << EOF
declaracion 1;
declaracion 2;
.
.
declaracion n;
EOF
PostgreSQL: Ejecutando SQL desde código Shell
Provee todos los comandos postgreSQL entre el bloque EOF
#!/bin/sh
bd="test"
usuario="test"
psql $db $usuario << EOF
SELECT * FROM test;
EOF
PostgreSQL: Usando Variables en SQL en un código Shell
Puedes usar variables shell dentro del bloque EOF
#!/bin/sh
db="test"
usuario="test"
cond="tgs"
psql $db $usuario << EOF
SELECT * FROM test WHERE col_name = '$cond';
EOF
Comentarios