Revision 12739
Added by Aaron Marcuse-Kubitza almost 11 years ago
trunk/lib/sh/db.sh | ||
---|---|---|
269 | 269 |
fi # load new aliases |
270 | 270 |
if self_being_included; then |
271 | 271 |
|
272 |
psql() # usage: [stdin=copy_pstdin_file] psql <<<"cmds, e.g. \copy from pstdin" |
|
272 |
psql() # usage: [stdin=copy_pstdin_file] [output_data=1] psql \ |
|
273 |
# <<<"cmds (eg. \copy from pstdin)" |
|
273 | 274 |
# SUDO_USER: when set, avoids outputting to /dev/fd/#, because this causes a |
274 | 275 |
# "Permission denied" error when running as sudo on Linux |
275 | 276 |
{ |
276 |
echo_func; kw_params stdin |
|
277 |
echo_func; kw_params stdin output_data
|
|
277 | 278 |
local verbose_ok="$(! isset SUDO_USER; exit2bool)"; echo_vars verbose_ok |
278 | 279 |
local verbose_="$(test "$verbose_ok" && can_log; exit2bool)" |
279 | 280 |
echo_vars verbose_ |
281 |
local data_bypasses_filter="$(test "$output_data" -a "$verbose_ok"; |
|
282 |
exit2bool)"; echo_vars data_bypasses_filter |
|
280 | 283 |
|
281 | 284 |
if test "$verbose_"; then set -- --echo-all --echo-hidden "$@"; fi |
282 | 285 |
local redirs=("${redirs[@]}" '40<&0' "0<${stdin:-&20}" '41>&1') |
... | ... | |
288 | 291 |
$(if test "$verbose_"; then echo NOTICE; else echo WARNING; fi);" |
289 | 292 |
cat |
290 | 293 |
)|cmd_log_fd=${verbose_ok:+1} pg_cmd --file /dev/fd/40 \ |
291 |
${verbose_ok:+--output /dev/fd/41 }--set ON_ERROR_STOP=1 --quiet "$@" \
|
|
294 |
${data_bypasses_filter:+--output /dev/fd/41 }--set ON_ERROR_STOP=1 --quiet "$@"\
|
|
292 | 295 |
|| verbosity_min=2 die_error_hidden |
293 | 296 |
# --output is for query *results*, not echoed statements |
294 | 297 |
} |
... | ... | |
299 | 302 |
mk_select_var |
300 | 303 |
local pg_copy_format="${pg_copy_format-CSV HEADER}" |
301 | 304 |
|
302 |
psql "$@" <<<"COPY ($query) TO STDOUT $pg_copy_format;" |
|
305 |
output_data=1 psql "$@" <<<"COPY ($query) TO STDOUT $pg_copy_format;"
|
|
303 | 306 |
} |
304 | 307 |
|
305 | 308 |
pg_header() |
Also available in: Unified diff
fix: lib/sh/db.sh: psql(): added $output_data switch analogous to what mysql() has. this causes query results of eg. void-returning functions to be correctly filtered by the logging mechanism, rather than output to stdout.