Wenn ich das tue, bekomme CAST(1 AS SIGNED INTEGER)
ich immer eine BIGINT
Rücksendung, zum Beispiel:
$ mysql -u root -p --column-type-info
Enter password:
--- Copyright and help message snipped for brevity ---
mysql> select cast(1 as signed integer);
Field 1: `cast(1 as signed integer)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: LONGLONG <== LONGLONG i.e. 64 bit integer
Collation: binary (63)
Length: 1
Max_length: 1
Decimals: 0
Flags: NOT_NULL BINARY NUM
+---------------------------+
| cast(1 as signed integer) |
+---------------------------+
| 1 |
+---------------------------+
1 row in set (0.00 sec)
Ich hätte erwartet, dass der Rückgabetyp aus dieser Umwandlung eine LONG
(32-Bit-Ganzzahl) ist.
Wenn ich eine Spalte aus einer Tabelle mit einem auswähle, INT
sehe ich, dass es sich tatsächlich nur um Folgendes handelt LONG
:
mysql> describe contact;
+------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------+------+-----+---------+----------------+
| contact_id | int(11) | NO | PRI | NULL | auto_increment |
== remainder of table snipped ==
mysql> select contact_id from contact where contact_id = 20;
Field 1: `contact_id`
Catalog: `def`
Database: `centreon`
Table: `contact`
Org_table: `contact`
Type: LONG <== LONG i.e. 32 bit integer
Collation: binary (63)
Length: 11
Max_length: 2
Decimals: 0
Flags: NOT_NULL PRI_KEY AUTO_INCREMENT NUM PART_KEY
+------------+
| contact_id |
+------------+
| 20 |
+------------+
1 row in set (0.00 sec)
mysql>
Wenn ich dieselbe Spalte in eine vorzeichenbehaftete Ganzzahl umwandle, wird erneut eine 64-Bit-Ganzzahl zurückgegeben:
mysql> select CAST(contact_id as signed integer) from contact where contact_id = 20;
Field 1: `CAST(contact_id as signed integer)`
Catalog: `def`
Database: ``
Table: ``
Org_table: ``
Type: LONGLONG
Collation: binary (63)
Length: 11
Max_length: 2
Decimals: 0
Flags: NOT_NULL BINARY NUM
+------------------------------------+
| CAST(contact_id as signed integer) |
+------------------------------------+
| 20 |
+------------------------------------+
1 row in set (0.00 sec)
Hier gibt es ein ähnlich gemeldetes Problem:
Leider erhält das OP keine klare Antwort.
Ist dies ein Fehler in der CAST()
Funktion oder ist dies beabsichtigt?
SIGNED [INTEGER]
im Abschnitt Der Typ für das Ergebnis kann einer der folgenden Werte sein : . Ist a SIGNED INTEGER
im Kontext einer CAST
nicht tatsächlich 32-Bit-Ganzzahl?
SELECT 1+1
führt zu a BIGINT
. Aber es erklärt immer noch nicht, warum es CAST()
sich im Gegensatz zur Dokumentation verhält (so wie ich es verstehe) und erzeugt einen BIGINT
geraden Wert, wenn es gebeten wird, auf SIGNED INTEGER
oder UNSIGNED INTEGER
auf einen einzelnen Skalarwert zu übertragen.