~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/functions/string/conversion.rst

  • Committer: Stewart Smith
  • Date: 2010-08-12 16:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: stewart@flamingspork.com-20100812164846-s9bhy47g60bvqs41
bug lp:611379 Equivalent queries with Impossible where return different results

The following two equivalent queries return different results in maria 5.2 and 5.3 (and identical results in mysql 5.5.5) :

SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` ;

SELECT * FROM ( SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` );

MariaDB returns 0 on the second query and NULL on the first, whereas MySQL returns NULL on both. In MariaDB, both EXPLAIN plans agree that "Impossible WHERE noticed after reading const tables"



We have some slightly different output in drizzle:

main.bug_lp611379 [ fail ]
drizzletest: At line 9: query 'explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
as t' failed: 1048: Column 'sum(distinct t1.a)' cannot be null

but the fix gets us the correct query results, although with slightly different execution plans.



This fix is directly ported from MariaDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Conversion Functions
2
 
====================
3
 
 
4
 
ASCII
5
 
-----
6
 

The ASCII(str) function returns the numeric value of the leftmost character of the string ’str’. It returns NULL if str is NULL. It works for 8-bit characters.
7
 
 
8
 
For example:  ::
9
 
 
10
 
        SELECT ASCII('0');
11
 
 
12
 
Returns 48 ::
13
 
 
14
 
        SELECT ASCII('d');
15
 
 
16
 
Returns 100
17
 
 
18
 
 
19
 
BIN
20
 
---
21
 

The BIN string function returns a string value that represents the binary value of N, where N is a longlong(BIGINT) number. This function is equivalent to CONV(N, 10 , 0). If the function return the null then N is null. 
22
 
 
23
 
Syntax:
24
 
 
25
 
BIN (N);
26
 
 
27
 
For exempt: ::
28
 
 
29
 
        SELECT BIN(12);
30
 
 
31
 
Returns: '1100'
32
 
 
33
 
 
34
 
CHAR
35
 
----
36
 

SQL CHAR function is the opposite of the ASCII function. It converts an integer in range 0-255 into a ASCII character. It returns a string (the character), given the integer value. This function skips NULL values.   

37
 
For example: ::
38
 
 
39
 
        SELECT CHAR(65) AS ch_65;
40
 
 
41
 
Returns "A"

42
 
 
43
 
HEX()
44
 
-----
45
 
 
46
 
This string function returns the hexadecimal (base-16) representation of a string or decicmal argument. Each character in the string argument is converted to two hexadecimal digits. If the argument is numeric, HEX() returns a hexadecimal string representation of the value as a BIGINT number.
47
 
 
48
 
Using HEX for numeric values: ::
49
 
 
50
 
        SELECT HEX(255);
51
 
 
52
 
Returns: FF
53
 
 
54
 
Using HEX for string values: ::
55
 
 
56
 
        SELECT HEX('Drizzle');
57
 
 
58
 
Returns: 4452495A5AHc45
59
 
 
60
 
(To better understand this output, you can use an :doc:`../../resources/ascii_chart` that includes both Hexadecimal and character values.)
61
 
 
62
 
 
63
 
UNHEX()
64
 
-------
65
 
 
66
 
UNHEX converts each pair of hexadecimal digits to a character. For a string argument, UNHEX() is the inverse operation of HEX(str).
67
 
 
68
 
Instead of converting each character in the string argument to hex digits, it interprets each pair of characters in the argument as a hexadecimal number and converts it to the character represented by the number. The return value is a binary string. ::
69
 
 
70
 
        SELECT UNHEX('4452495A5AHc45');
71
 
 
72
 
Returns 'drizzle' ::
73
 
 
74
 
        SELECT UNHEX(HEX('string'));
75
 
 
76
 
Returns 'string' ::
77
 
 
78
 
        SELECT HEX(UNHEX('1267'));
79
 
 
80
 
Returns '1267'
81
 
 
82
 
The characters in the argument string must be legal hexadecimal digits: '0' .. '9', 'A' .. 'F', 'a' .. 'f'. If the argument contains any non-hexadecimal digits, the result is NULL: ::
83
 
 
84
 
        SELECT UNHEX('GG');
85
 
 
86
 
Returns NULL
87
 
 
88
 
 
89
 
 
90
 
LOWER()                   
91
 
Return the argument in lowercase
92
 
 
93
 
 
94
 
LCASE()                   
95
 
Synonym for LOWER()
96
 
 
97
 
 
98
 
UCASE()                   
99
 
Synonym for UPPER()
100
 
 
101
 
 
102
 
UPPER()                   
103
 
Convert to uppercase