Thread: Possible bug in parsing
Can anyone explain the following: hannu=> select 1 + 2 + 3 + 4; ?column? -------- 10 (1 row) works fine, but: hannu=> select '1' || '2' || '3'; ERROR: parser: parse error at or near "||" hannu=> select ('1' || '2') || '3'; NOTICE: there is more than one operator || for types NOTICE: unknown and unknown. You will have to retype this query ERROR: using an explicit cast hannu=> select ('1'::text || '2') || '3'; ?column? -------- 123 (1 row) I understand the 'there is more than one operator' errors, but what is so different between operators + and || ? Hannu
> > > I understand the 'there is more than one operator' errors, but > > > what is so different between operators + and || ? > > Yes I know that, but why are they so different that I can have > ARG1 op ARG2 op ARG3 > with + but not with || Ah! I *thought* that was a silly question, and as usual that's because I didn't understand the question :) They behave differently because the "+" operator is allowed to be "left-associative", since its behavior is well-defined mathematically, while the "||" operator falls into a broad class of multi-character operators in the parser which are "non-associative". So, the parser does not know whether to evaluate left-to-right or right-to-left and throws an error instead. > I actually found this while trying to find out how characters in > strings are escaped and if \0 is supported in them. > > Is there some docs on escaping characters, and if not then where do > you think it should go in docs ? I believe that there are no docs on escaping characters and I would suggest that docs for it should go into the user's guide in the section on character data types (since it applies to all of them). That would be in doc/src/sgml/datatype.sgml, probably in a "Sect2" at the end of the "Sect1" on "Character Types" and just before the "Sect1" on "Date/Time Types". If you find it difficult to work with that source document, you can just type the information and I can help to integrate it into the doc. btw, I think that the escape conventions for strings need some work; the fact that the characters are re-escaped when output makes it easy to do a dump/reload but sort of defeats the usefulness of escaping anything in the first place. - Tom
Thomas G. Lockhart wrote: > > I understand the 'there is more than one operator' errors, but > > what is so different between operators + and || ? > > ?? They are different operators, that's why. The "+" is addition, and > the "||" is defined in SQL92 to be string concatenation. > > Yes I know that, but why are they so different that I can have ARG1 op ARG2 op ARG3 with + but not with || Hannu
Thomas G. Lockhart wrote: > > I understand the 'there is more than one operator' errors, but > > what is so different between operators + and || ? > > ?? They are different operators, that's why. The "+" is addition, and > the "||" is defined in SQL92 to be string concatenation. I actually found this while trying to find out how characters in strings are escaped and if \0 is supported in them. Is there some docs on escaping characters, and if not then where do you think it should go in docs ? Hannu
> I understand the 'there is more than one operator' errors, but > what is so different between operators + and || ? ?? They are different operators, that's why. The "+" is addition, and the "||" is defined in SQL92 to be string concatenation. - Tom