Yii2: Query Builder - Wrong quoting when using decimal value in select

Created on 4 Jan 2019  路  4Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

...
(new Query())
            ->select([
                'overtime' => '1.3',
            ])
...

or

...
(new Query())
            ->select([
                "'1.3' AS `overtime`",
            ])
...

What is the expected result?

the generated query to be:

SELECT '1.3' AS `overtime` ...

What do you get instead?

the generated query is:

SELECT `1`.`3` AS `overtime` ...

Additional info

| Q | A
| ---------------- | ---
| Yii version | 2.0.16-dev
| PHP version | 7.2.10

db to be verified

All 4 comments

I don't think that this is a bug - if you want avoid quoting you should use Expression - this is explained in select() documentation. See https://github.com/yiisoft/yii2/pull/17017/files#r245482467

$q = (new Query())
    ->select([new Expression("'overtime' AS '1.3'")])
    ->from('sometable');
$comm = $q->createCommand();
var_dump($comm->getSql());exit;

I have got SELECT 'overtime' AS '1.3' FROM "sometable" as result

Second case isn't a bug as @rob006 noted.

@tsanchev what's the problem with

(new Query())
            ->select([
                'overtime' => '1.3',
            ])

?

@samdark With both i've got the same result, but I guess i should use Expression so it's not a bug

Was this page helpful?
0 / 5 - 0 ratings