Skip to content

Commit d0c56ab

Browse files
authored
Merge pull request duckdb#86 from Mytherin/issue65
Fix duckdb#65: use length instead of max_length when computing decimal width - as when using mysql_query max_length corresponds to the max length in the result set, as opposed to the max length of the field type
2 parents 383f192 + 559e121 commit d0c56ab

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/mysql_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ LogicalType MySQLUtils::FieldToLogicalType(ClientContext &context, MYSQL_FIELD *
392392
break;
393393
case MYSQL_TYPE_DECIMAL:
394394
case MYSQL_TYPE_NEWDECIMAL:
395-
type_data.precision = int64_t(field->max_length) - 2; // -2 for minus sign and dot
395+
type_data.precision = int64_t(field->length) - 2; // -2 for minus sign and dot
396396
type_data.scale = field->decimals;
397397
type_data.type_name = "decimal";
398398
break;

test/sql/mysql_query.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,11 @@ SELECT * FROM mysql_query('simple', 'SELECT * FROM datetime_tbl')
167167
1000-01-01 1000-01-01 00:00:00 1970-01-01 06:00:01+00 -838:59:59 2155
168168
9999-12-31 9999-12-31 23:59:59 2038-01-19 04:14:07+00 838:59:59 2000
169169
NULL NULL NULL NULL NULL
170+
171+
# issue #65 - Decimal data type conversion issue with mysql_query function
172+
query II
173+
SELECT * FROM mysql_query('simple', 'SELECT * FROM tbl_issue65')
174+
----
175+
1 1.11
176+
2 2.22
177+
3 3.33

test/test_data.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,6 @@ VALUES (
149149
ST_GeomFromText('MULTIPOLYGON(((0 5, 2 5, 2 7, 0 7, 0 5)))'),
150150
ST_GeomFromText('GEOMETRYCOLLECTION EMPTY')
151151
);
152+
153+
CREATE TABLE tbl_issue65 (col1 int, col2 decimal(5,2));
154+
insert into tbl_issue65 values (1,1.11), (2,2.22), (3,3.33);

0 commit comments

Comments
 (0)