pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
bug: evil autoConcat when each string is on new line
8+ messages / 7 participants
[nested] [flat]

* bug: evil autoConcat when each string is on new line
@ 2019-04-24 11:35  Jan Skydánek <jan.skydanek@betsys.com>
  0 siblings, 2 replies; 8+ messages in thread

From: Jan Skydánek @ 2019-04-24 11:35 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

Does not work (as expected):
SELECT 'aaa' 'bbb' 'ccc';

Works (definitely NOT expected):
SELECT
'aaa'
'bbb'
'ccc'
; -- result is: 'aaabbbccc'


I really hope this behavior is not intentional.

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-24 11:56  Vik Fearing <vik.fearing@2ndquadrant.com>
  parent: Jan Skydánek <jan.skydanek@betsys.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Vik Fearing @ 2019-04-24 11:56 UTC (permalink / raw)
  To: Jan Skydánek <jan.skydanek@betsys.com>; pgsql-bugs@lists.postgresql.org

On 24/04/2019 13:35, Jan Skydánek wrote:
> Does not work (as expected):
> SELECT 'aaa' 'bbb' 'ccc';
> 
> Works (definitely NOT expected):
> SELECT
> 'aaa'
> 'bbb'
> 'ccc'
> ; -- result is: 'aaabbbccc'
> 
> 
> I really hope this behavior is not intentional.
Hi.

Yes, this behavior is intentional as mandated by the SQL spec.
-- 
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-24 12:44  Alvaro Herrera <alvherre@2ndquadrant.com>
  parent: Jan Skydánek <jan.skydanek@betsys.com>
  1 sibling, 2 replies; 8+ messages in thread

From: Alvaro Herrera @ 2019-04-24 12:44 UTC (permalink / raw)
  To: Jan Skydánek <jan.skydanek@betsys.com>; +Cc: pgsql-bugs@lists.postgresql.org

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





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-24 14:26  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 0 replies; 8+ messages in thread

From: Tom Lane @ 2019-04-24 14:26 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Jan Skydánek <jan.skydanek@betsys.com>; pgsql-bugs@lists.postgresql.org

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> 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.

Yeah.  Quoting from SQL99:

         <separator> ::= { <comment> | <white space> }...

         <character string literal> ::=
              [ <introducer><character set specification> ]
              <quote> [ <character representation>... ] <quote>
                [ { <separator> <quote> [ <character representation>... ] <quote> }... ]

         Syntax Rules

         1) In a <character string literal> or <national character string
            literal>, the sequence:

              <quote> <character representation>... <quote>
              <separator> <quote> <character representation>... <quote>

            is equivalent to the sequence

              <quote> <character representation>... <character
              representation>... <quote>

            NOTE 47 - The <character representation>s in the equivalent
            sequence are in the same sequence and relative sequence as in
            the original <character string literal>.


         5) In a <character string literal>, <national character string
            literal>, <bit string literal>, <binary string literal>, or <hex
            string literal>, a <separator> shall contain a <newline>.


Don't ask us, we just implement it.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-24 23:13  raf@raf.org
  parent: Alvaro Herrera <alvherre@2ndquadrant.com>
  1 sibling, 1 reply; 8+ messages in thread

From: raf@raf.org @ 2019-04-24 23:13 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

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






^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-25 08:18  Francisco Olarte <folarte@peoplecall.com>
  parent: raf@raf.org
  0 siblings, 1 reply; 8+ messages in thread

From: Francisco Olarte @ 2019-04-25 08:18 UTC (permalink / raw)
  To: raf@raf.org; +Cc: pgsql-bugs@lists.postgresql.org

On Thu, Apr 25, 2019 at 1:13 AM <raf@raf.org> wrote:

> 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.

In C, IIRC, it is also useful when combined with the stringification
construct of the preprocessor ( #xxx => "xxx" ) to construct things
like long messages ( evaluated at compile time, like #define
PRINT_INT(v) printf( #v "=%d\n",(v))  ).

> 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. :-)

Actually when I first saw this it made me curious and I searched for
"string constants" in the doc, the second paragraph in "4.1.2.1.
String Constants" says "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:", but I suppose reading TFM before reporting a bug is
getting too old fashioned ( and one of my top reasons for using
postgres is doc quality ).

> 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. :-)

SQL std is really puzzling and irregular. My usual comment when
reading some of it is "what do these guys smoke, I want some of it".
For me is the type of language which makes for great looking examples
in the manual but when you use it is so irregular to learn and when
you implement is difficult to parse. I mean, substring( "hello" from 1
for 2) may look great, but substr("hello", 1, 2) is, for me, much
regular and easier to remember ( learning the parameters is hard
enough without having to learn the special delimiters too ). String
constant concatenation requiring at least one newline among the
whitespace is one of these things. Although it MAY have a good reason
for it.

Francisco Olarte.





^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-25 09:43  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Pavel Stehule @ 2019-04-25 09:43 UTC (permalink / raw)
  To: Francisco Olarte <folarte@peoplecall.com>; +Cc: raf@raf.org; pgsql-bugs@lists.postgresql.org

čt 25. 4. 2019 v 10:18 odesílatel Francisco Olarte <folarte@peoplecall.com>
napsal:

> On Thu, Apr 25, 2019 at 1:13 AM <raf@raf.org> wrote:
>
> > 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.
>
> In C, IIRC, it is also useful when combined with the stringification
> construct of the preprocessor ( #xxx => "xxx" ) to construct things
> like long messages ( evaluated at compile time, like #define
> PRINT_INT(v) printf( #v "=%d\n",(v))  ).
>
> > 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. :-)
>
> Actually when I first saw this it made me curious and I searched for
> "string constants" in the doc, the second paragraph in "4.1.2.1.
> String Constants" says "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:", but I suppose reading TFM before reporting a bug is
> getting too old fashioned ( and one of my top reasons for using
> postgres is doc quality ).
>
> > 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. :-)
>
> SQL std is really puzzling and irregular. My usual comment when
> reading some of it is "what do these guys smoke, I want some of it".
> For me is the type of language which makes for great looking examples
> in the manual but when you use it is so irregular to learn and when
> you implement is difficult to parse. I mean, substring( "hello" from 1
> for 2) may look great, but substr("hello", 1, 2) is, for me, much
> regular and easier to remember ( learning the parameters is hard
> enough without having to learn the special delimiters too ). String
> constant concatenation requiring at least one newline among the
> whitespace is one of these things. Although it MAY have a good reason
> for it.
>

There is a impact of some older traditions. Originally SQL was a language
for ending users, it was not designed for developers.

Regards

Pavel


> Francisco Olarte.
>
>
>

^ permalink  raw  reply  [nested|flat] 8+ messages in thread

* Re: bug: evil autoConcat when each string is on new line
@ 2019-04-25 14:03  Francisco Olarte <folarte@peoplecall.com>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 8+ messages in thread

From: Francisco Olarte @ 2019-04-25 14:03 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: raf@raf.org; pgsql-bugs@lists.postgresql.org

Pavel:

On Thu, Apr 25, 2019 at 11:43 AM Pavel Stehule <pavel.stehule@gmail.com> wrote:
>> SQL std is really puzzling and irregular. ....
.....Rest of rant snipped.
> There is a impact of some older traditions. Originally SQL was a language for ending users, it was not designed for developers.

Yes, I know where it comes from. It reminds me a lot of when I as
learning COBOL ( on punched cards). Seeing the evolution I think
people assumed that adding a little verbosity and words instead of
plain commas here and there would make it easier, but IMO it makes for
great presentation material but harder to use, both for end users and
for profesional developers. And it's not the only one, IE, I've always
thought that the format of HTTP headers is great for a casual reading
and/or presenting examples in RFCs, but needlesly difficult to parse
or generate, I group that with glossy screens, better for shop
display, worse for everyday use in my experience.

Regards.
    Francisco Olarte.





^ permalink  raw  reply  [nested|flat] 8+ messages in thread


end of thread, other threads:[~2019-04-25 14:03 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-04-24 11:35 bug: evil autoConcat when each string is on new line Jan Skydánek <jan.skydanek@betsys.com>
2019-04-24 11:56 ` Vik Fearing <vik.fearing@2ndquadrant.com>
2019-04-24 12:44 ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-04-24 14:26   ` Tom Lane <tgl@sss.pgh.pa.us>
2019-04-24 23:13   ` raf@raf.org
2019-04-25 08:18     ` Francisco Olarte <folarte@peoplecall.com>
2019-04-25 09:43       ` Pavel Stehule <pavel.stehule@gmail.com>
2019-04-25 14:03         ` Francisco Olarte <folarte@peoplecall.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox