Revision 9646
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/sh/db.sh | ||
---|---|---|
215 | 215 |
|
216 | 216 |
### PostgreSQL |
217 | 217 |
|
218 |
psql() # usage: [stdin=copy_pstdin_file] psql <<<"cmds, e.g. \copy from pstdin" |
|
219 |
{ |
|
220 |
echo_func; kw_params stdin |
|
221 |
|
|
222 |
if can_log; then set -- --echo-all --echo-hidden "$@"; fi |
|
223 |
local redirs=("${redirs[@]}" '10<&0' "0<${stdin:-&20}" '13>&1') |
|
224 |
# not 11 (for 13) because it gives a "/dev/fd/11: Bad file descriptor" |
|
225 |
# error when 11 is set with exec right before the command instead of on |
|
226 |
# the subshell it's executed in |
|
227 |
( |
|
228 |
if can_log; then cat <<'EOF' |
|
229 |
\timing on |
|
230 |
SET client_min_messages = NOTICE; |
|
231 |
EOF |
|
232 |
fi |
|
233 |
cat |
|
234 |
)|cmd_log_fd=1 command psql --file /dev/fd/10 --output /dev/fd/13 "$@" |
|
235 |
# --output is for query *results*, not echoed statements |
|
236 |
} |
|
237 |
|
|
218 | 238 |
pg_export() |
219 | 239 |
{ |
220 | 240 |
echo_func |
Also available in: Unified diff
lib/sh/db.sh: added psql(), which replaces psql_script_vegbien and psql_verbose_vegbien for general connections. it also supports separate command and stdin files, to allow using `\copy from pstdin`, with pstdin pointing to a separate, EOF-terminated CSV file instead of inlined with the command and terminated with the \. escape (which may be contained within the CSV file itself).