Mysql
 sql >> Database >  >> RDS >> Mysql

1 è sempre uguale a "1" in SQL?

SELECT 1='1'TRUE da '1' è un costruttore corretto per INT in tutte le implementazioni a me note.

Ma SQL usa una tipizzazione rigorosa, vedi che:

# SELECT 1=CAST('1' AS TEXT);
ERROR:  operator does not exist: integer = text
LINE 1: SELECT 1=CAST('1' AS TEXT);
                ^
HINT:  No operator matches the given name and argument type(s). You might need to add  explicit type casts.

Per quanto riguarda lo standard (SQL 92, 99 e 2003) sembra essere sbagliato:

     <literal> ::=
            <signed numeric literal>
          | <general literal>

     <general literal> ::=
            <character string literal>
          | <national character string literal>
          | <bit string literal>
          | <hex string literal>
          | <datetime literal>
          | <interval literal>

     <signed numeric literal> ::=
          [ <sign> ] <unsigned numeric literal>

     <unsigned numeric literal> ::=
            <exact numeric literal>
          | <approximate numeric literal>

     <exact numeric literal> ::=
            <unsigned integer> [ <period> [ <unsigned integer> ] ]
          | <period> <unsigned integer>

     <unsigned integer> ::= <digit>...

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

perché <quote> è contenuto solo in <bit string literal> , <hex string literal> , ... ma non in valori letterali numerici...