Обсуждение: Bug in parser?

Поиск
Список
Период
Сортировка

Bug in parser?

От
Gerhard Dieringer
Дата:
============================================================================
                        POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name        :    Gerhard Dieringer
Your email address    :    Gerhard.Dieringer@nexgo.de


System Configuration
---------------------
  Architecture (example: Intel Pentium)      :Dual Intel Pentium II

  Operating System (example: Linux 2.0.26 ELF)     : Linux 2.2.16

  PostgreSQL version (example: PostgreSQL-7.3.3):   PostgreSQL-7.3.3

  Compiler used (example:  gcc 2.95.2)        :   gcc-Version 3.3


Please enter a FULL description of your problem:
------------------------------------------------
Inconsistent results when calling '+' operator with text arguemts
The last 4 results (f.e. '1' + '2' -> 'c') are very strange.



Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
select 1 + '2' as result;
 result
--------
      3
(1 row)

select 1 + '2.3' as result;
psql:error.sql:2: ERROR:  pg_atoi: error in "2.3": can't parse ".3"
select 1.5 + '2' as result;
 result
--------
    3.5
(1 row)

select 1.4 + '2.3' as result;
 result
--------
    3.7
(1 row)

select '1' + '2' as result;
 result
--------
 c
(1 row)

select '1' + '2.3' as result;
 result
--------
 c
(1 row)

select '1.5' + '2' as result;
 result
--------
 c
(1 row)

select '1.4' + '2.3' as result;
 result
--------
 c
(1 row)





If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------
Sorry :-((

Re: Bug in parser?

От
Stephan Szabo
Дата:
On 31 May 2003, Gerhard Dieringer wrote:

>
>
> ============================================================================
>                         POSTGRESQL BUG REPORT TEMPLATE
> ============================================================================
>
>
> Your name        :    Gerhard Dieringer
> Your email address    :    Gerhard.Dieringer@nexgo.de
>
>
> System Configuration
> ---------------------
>   Architecture (example: Intel Pentium)      :Dual Intel Pentium II
>
>   Operating System (example: Linux 2.0.26 ELF)     : Linux 2.2.16
>
>   PostgreSQL version (example: PostgreSQL-7.3.3):   PostgreSQL-7.3.3
>
>   Compiler used (example:  gcc 2.95.2)        :   gcc-Version 3.3
>
>
> Please enter a FULL description of your problem:
> ------------------------------------------------
> Inconsistent results when calling '+' operator with text arguemts
> The last 4 results (f.e. '1' + '2' -> 'c') are very strange.

'1'+'2' is pretty meaningless.  In the other cases you're giving a type
that has a meaningful + operator so it's trying to convert  the quoted
argument to an appropriate type for +.  In the '1'+'2' case it's
converting to "char" (single character) and adding those which seems
marginally reasonable to me (although I think that "char" is pretty
silly).

I'm not sure what you expected '1'+'2' to give though, concatenation is ||
and I can't think of something meaningful to do with it.

Re: Bug in parser?

От
Tom Lane
Дата:
Gerhard Dieringer <Gerhard.Dieringer@arcor.de> writes:
> Inconsistent results when calling '+' operator with text arguemts

I suspect you are looking for the '||' operator, which is the SQL-standard
spelling of concatenation.  '+' ends up invoking the one-byte-"char"
datatype's addition operator.

            regards, tom lane