Alvaro Herrera wrote:
> On 2019-Apr-24, Jan Skydánek wrote:
>
> > Works (definitely NOT expected):
> > SELECT
> > 'aaa'
> > 'bbb'
> > 'ccc'
> > ; -- result is: 'aaabbbccc'
> >
> > I really hope this behavior is not intentional.
>
> Actually it's the SQL standard that defines that it must work in exactly
> that way.
>
> --
> Álvaro Herrera https://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Perhaps what Jan meant to do was:
select
'aaa',
'bbb',
'ccc'
;
Many languages automatically concatenate consecutive
string literals, not just SQL. Even C does it. Probably
because there's no other useful interpretation of what
multiple consecutive string literals means. It's either
concatenate them or treat it as a syntax error.
Concatenating can be useful so it wins.
Actually, I just tried that command on a single line
and that was a syntax error. So what do I know?
Presumably the SQL standard says to do that as well. :-)
It does seem like an inconsistency. I wouldn't have
expected SQL to be so whitespace-dependant but there'll
be a good reason for it somewhere. And, again, it's not
the only language where newlines matter. :-)
cheers,
raf