1. 6
  1. 2

    Indentation is one way to avoid escaping. Dynamic quote sequences is another way. Compared to indentation, the advantage of dynamic quote sequences is that you don’t even need indentation, and can therefore cut-and-paste freely with no special editor support for indentation-aware pasting. The disadvantage is that you need to come up with a quote sequence, which can feel less clean than indentation. I tried explaining it here: https://axelsvensson.com/escaping-escaping/

    1. 1

      Interesting. I think I use a version of “dynamic quote escaping”. For example, I often will save delimited data as “table |” or “table ,” to indicate that the following data is pipe or comma delimited.

      Would you say it is equivalent to: encode(string) => fn(encodedString, escapeRules)

      Where encode scans the string to be encoded, chooses a safe delimiter(s), and then returns the untouched string along with the delimiting rules?

      1. 2

        Not sure I understand the question well enough to answer; what is fn?.

        You could certainly create a string quoting function that takes an arbitrary string, scans it to choose a safe delimiter, and uses that to return a quoted form of the string without any escaping. Such a quoting function implemented in plpgSQL could for example function as follows:

        => "$$abc$$"
        => "$a$ab$$cd$a$"