13

I would like to paste

  123
  456
  789

into psql and to store multi-line string in some variable (ie. :str) for later use.

Is that possible? Now I'm getting unterminated quoted string error.

mpapec
  • 49,466
  • 8
  • 63
  • 119

1 Answers1

23

A little clunky, but in version 9.3 and up, you can do it with \gset in conjunction with a dollar-quoted literal:

SELECT
$$123
456
789$$ AS str \gset
Nick Barnes
  • 17,796
  • 3
  • 46
  • 57