Revision 10763
Added by Aaron Marcuse-Kubitza about 11 years ago
db.sh | ||
---|---|---|
239 | 239 |
fi # load new aliases |
240 | 240 |
if self_being_included; then |
241 | 241 |
|
242 |
psql() # usage: [stdin=copy_pstdin_file] psql <<<"cmds, e.g. \copy from pstdin" |
|
242 |
# usage: pg_*() { ...; pg_cmd "$@"; } (uses alias) |
|
243 |
function pg_cmd() # usage for fn: pg_*() { ...; pg_cmd cmd "$@"; } |
|
244 |
# auto-adds connection/login opts when specified |
|
243 | 245 |
{ |
244 |
echo_func; kw_params stdin
|
|
246 |
echo_func |
|
245 | 247 |
|
246 | 248 |
use_pg |
247 | 249 |
log- 2 |
... | ... | |
251 | 253 |
local PGDATABASE="$database"; export PGDATABASE |
252 | 254 |
log+ 2 |
253 | 255 |
|
256 |
command "time" "$@" |
|
257 |
} |
|
258 |
alias pg_cmd='"pg_cmd" "${FUNCNAME%%__*}"' |
|
259 |
|
|
260 |
fi # load new aliases |
|
261 |
if self_being_included; then |
|
262 |
|
|
263 |
psql() # usage: [stdin=copy_pstdin_file] psql <<<"cmds, e.g. \copy from pstdin" |
|
264 |
{ |
|
265 |
echo_func; kw_params stdin |
|
266 |
|
|
254 | 267 |
if can_log; then set -- --echo-all --echo-hidden "$@"; fi |
255 | 268 |
local redirs=("${redirs[@]}" '40<&0' "0<${stdin:-&20}" '41>&1') |
256 | 269 |
( |
... | ... | |
262 | 275 |
EOF |
263 | 276 |
fi |
264 | 277 |
cat |
265 |
)|cmd_log_fd=1 command psql --file /dev/fd/40 --output /dev/fd/41 \
|
|
278 |
)|cmd_log_fd=1 pg_cmd --file /dev/fd/40 --output /dev/fd/41 \
|
|
266 | 279 |
--set ON_ERROR_STOP=1 --quiet "$@" |
267 | 280 |
# --output is for query *results*, not echoed statements |
268 | 281 |
} |
Also available in: Unified diff
lib/sh/db.sh: added pg_cmd() (analogous to mysql_cmd() for PostgreSQL), and use it in psql(), so that other PostgreSQL operations can use this to set the PG* connection/login vars