While I appreciate that you've found a workaround, and I don't actually have an alternative solution to propose here, it strikes me as unfortunate that you have to go to the lengths of base64 encoding something to handle escaping. Does anything in Org actually have a concept of escaping?
Cheers, Derek On Fri, Sep 25, 2026 at 6:52 PM Tim Landscheidt <[email protected]> wrote: > 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 > > -- +---------------------------------------------------------------+ | Derek Chen-Becker | | GPG Key available at https://keybase.io/dchenbecker and | | https://pgp.mit.edu/pks/lookup?search=derek%40chen-becker.org | | Fngrprnt: EB8A 6480 F0A3 C8EB C1E7 7F42 AFC5 AFEE 96E4 6ACC | +---------------------------------------------------------------+
