jeff@goaldriven.com writes:
> Running the query below will show how the delimiter for the current row is
> actually the subsequent rows delimiter.
Hmm, well, the documentation for string_agg doesn't say what happens when
the "delimiter" argument varies across rows; but a quick look at the code
finds that the first-call delimiter isn't actually used at all, and on
subsequent calls the delimiter is appended to the running result before
the associated value is. Which seems to me to be at least as reasonable,
and certainly a great deal easier to implement, as what you seem to have
in mind. Can you offer a principled argument why it should be the other
way around?
regards, tom lane