linux user group brescia

immagine del castello

Archivio della mailing list

mysql, che bel pezzo di software (di m.....)!

lbell a tsc4.com lbell a tsc4.com
Gio 3 Ago 2006 15:56:09 UTC
Da quello che mi ricordo di SQL le union vengono fatte tra campi compatibili tra
loro in tipo e dimensione.
Se i campi non coincidono, occorre risolvere la situazione in un modo o
nell\'altro a discrezione del database. Per risolvere il problema in modo pulito
occorre effettuare queries con campi dello stesso tipo nelle due select. Riporto
un passo del manuale di MYSQL 5

<<If the data types of corresponding SELECT  columns do not match, the types and
lengths of the columns in the UNION result take into account the values
retrieved by all of the SELECT  statements. For example, consider the following:

mysql> SELECT REPEAT(\'a\',1) UNION SELECT REPEAT(\'b\',10);
+---------------+
| REPEAT(\'a\',1) |
+---------------+
| a             |
| bbbbbbbbbb    |
+---------------+

(In some earlier versions of MySQL, only the type and length from the first
SELECT would have been used and the second row would have been truncated to a
length of 1.)  >>


Quindi sembra rientrare tutto nella norma. Per confronto SQL Server 2005 riporta
a	ciao
ciao	b

come risultato

ciao

> con mysql5.0
> 
> mysql> select \'a\',\'ciao\' union select \'ciao\',\'b\';
> +------+------+
> | a    | ciao |
> +------+------+
> | a    | ciao | 
> | ciao | b    | 
> +------+------+
> 2 rows in set (0.00 sec)
> 
> con mysql4.0.24
> mysql> select \'a\',\'ciao\' union select \'ciao\',\'b\';
> +---+------+
> | a | ciao |
> +---+------+
> | a | ciao | 
> | c | b    | 
> +---+------+
> 2 rows in set (0.00 sec)
> 
> la seconda query e\' ovviamente pesantemente sbagliata.
> quale altra cagata ci riservera\' domani mysql?




Maggiori informazioni sulla lista Lug