Mysql
 sql >> Base de données >  >> RDS >> Mysql

1 est-il toujours égal à '1' en SQL ?

SELECT 1='1' donne TRUE depuis '1' est un constructeur correct pour INT dans toutes les implémentations que je connais.

Mais SQL utilise un typage strict, voyez ceci :

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

Concernant le standard (SQL 92, 99 &2003) cela semble faux :

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

parce que <quote> est uniquement contenu dans <bit string literal> , <hex string literal> , ... mais pas en littéraux numériques...