I wrote:
> […]
> But it turns out that the solution is much more simple: Con-
> vert the argument to a Base64 string and then decode it in
> PostgreSQL and Bash separately, but similarly:
> | #+NAME: maintenance-task
> | #+HEADERS: :var pb64=(base64-encode-string (encode-coding-string
> (completing-read "Parameter: " '("a" "b" "c")) 'utf-8))
> | #+BEGIN_SRC sql :engine postgres :cmdline --no-psqlrc -q
> | BEGIN WORK;
> | \set filedata `cat /path/to/"$(printf %s '$pb64' | base64 -d)".txt`
> | \set p `printf %s '$pb64' | base64 -d`
> | SELECT :'p', :'filedata';
> | COMMIT WORK;
> | #+END_SRC
> (Strictly speaking, the "'"s around "$pb64" should not be
> necessary.)
> This has worked for me, so I thought I post about it here in
> case someone has (had) a similar problem.
This does not work if the argument is so long that
base64-encode-string wraps it as then $pb64 will contain a
newline and psql barfs on:
| \set test `echo "Test
| with
| newlines"`
To avoid that, pass t as base64-encode-string's second argu-
ment NO-LINE-BREAK:
> | #+HEADERS: :var pb64=(base64-encode-string (encode-coding-string
> (completing-read "Parameter: " '("a" "b" "c")) 'utf-8) t)
Tim