psql "$SERVICE" --echo-queries <<'SQL' prepare tmp as SELECT idx FROM generate_series(1, 20) gs (idx) WHERE 'short-circuit' != $1 AND idx BETWEEN $2 AND :$3;
That's untested, and probably wont work. The "execute tmp($1, $2, $3)" need to be passed to psql as-is, but $string_input, $start and $end need to be replaced in bash before its sent to psql. Maybe use \$1?
> AND idx BETWEEN $2 AND :$3; should be: AND idx BETWEEN $2 AND $3;
> That's untested, and probably wont work. The "execute tmp($1, $2, $3)" should be: execute tmp($string_input, $start, $end);
-Andy
Thanks! I got the gist even with the typo. I actually pondered about prepare/execute after hitting send. Am I correct in remembering that "CREATE TEMP TABLE" cannot be prepared? I was using the actual query with CREATE TEMP TABLE and then issuing "\copy" to dump the result out to the file. The limitation of copy to having to be written on a single line makes the intermediary temporary table seem almost a necessity.
I'd rather write the :'start'::integer than go through the prepare/execute cycle...