Revision 8834
Added by Aaron Marcuse-Kubitza over 11 years ago
lib/runscripts/local.run | ||
---|---|---|
18 | 18 |
psql () # usage: [file=...] [dir=...] self |
19 | 19 |
{ |
20 | 20 |
echo_func "$@" |
21 |
local dir="$dir" |
|
22 | 21 |
if test -n "$file"; then |
23 | 22 |
set -- --file "$file" "$@" |
24 |
: "${dir:=$(dirname "$file")}"
|
|
23 |
local dir="${dir:-$(dirname "$file")}"
|
|
25 | 24 |
fi |
26 |
: "${dir:=$top_dir}"
|
|
25 |
local dir="${dir:-$top_dir}"
|
|
27 | 26 |
|
28 | 27 |
local psql_cmd="psql_$(if log_sql; then echo verbose; else echo script; fi)_vegbien" |
29 | 28 |
(cat <<EOF |
lib/util.sh | ||
---|---|---|
166 | 166 |
echo_func "$@" |
167 | 167 |
if test -z "$source"; then |
168 | 168 |
: "${table:?}"; mk_table_esc |
169 |
if test -z "$limit"; then source="$table_esc" |
|
170 |
else source="(SELECT * FROM $table_esc LIMIT $limit)" |
|
169 |
if test -z "$limit"; then local source="$table_esc"
|
|
170 |
else local source="(SELECT * FROM $table_esc LIMIT $limit)"
|
|
171 | 171 |
fi |
172 | 172 |
fi |
173 |
: "${pg_copy_format=CSV HEADER}"
|
|
173 |
local pg_copy_format="${pg_copy_format-CSV HEADER}"
|
|
174 | 174 |
|
175 | 175 |
psql "$@" <<<"COPY $source TO STDOUT $pg_copy_format;" |
176 | 176 |
} |
Also available in: Unified diff
bugfix: *{.sh,run}: use `local` when setting default values for params to prevent these values from leaking into the calling context, where it may have unexpected effects (e.g. pg_copy_to would permanently set $source, which would then be used on the next invocation of pg_copy_to instead of regenerating $source from the next $table value). this involves using ${var-default} or ${var:-default} to return the value to the local statement instead of setting it directly with ${var=default} or ${var:=default}.