I have observed that the following two queries are both valid in PostgreSQL, and each results in the same query result:
SELECT 'PostgreSQL is a powerful, ' ||
'open source object-relational ' ||
'database system.';
SELECT 'PostgreSQL is a powerful, '
'open source object-relational '
'database system.';
Those queries work both in both psql and DBeaver, giving
PostgreSQL is a powerful, open source object-relational database system.
I have been trying to determine if the second form, where the ||
string concatenation operator is omitted, is officially supported, but have been unable to find it documented anywhere. Stack Overflow answer https://stackoverflow.com/a/50884004/1179467 demonstrates that the ||
operator can also be omitted when defining a comment on an object.
Can the ||
operator be safely omitted between strings separated by newlines, or might this behavior be removed in a future release of PostgreSQL?
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS:
Two string constants that are only separated by whitespace with at least one newline are concatenated and effectively treated as if the string had been written as one constant. For example:
SELECT 'foo' 'bar';
is equivalent to:
SELECT 'foobar';
but:
SELECT 'foo' 'bar';
is not valid syntax. (This slightly bizarre behavior is specified by SQL; PostgreSQL is following the standard.)