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.
Use triple quotes to create a multiline string It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. Anything inside the enclosing Triple quotes will become part of one multiline string.
Syntax Using /* and */ symbols In PostgreSQL, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.
To create strings that span multiple lines, triple single quotes ''' or triple double quotes """ are used to enclose the string. ''' This string is on multiple lines within three single quotes on either side.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With