Open bartek5186 opened 9 years ago
asArray()
You have to pass an array to select for this to work:
$query->select(["st_x(location::geometry) as lon"]);
check the docs for more details:
http://www.yiiframework.com/doc-2.0/yii-db-query.html#select%28%29-detail Note that if you are selecting an expression like CONCAT(first_name, ' ', last_name), you should use an array to specify the columns. Otherwise, the expression may be incorrectly split into several parts.
I have tested it with Array too on beginning.
Its not working
$query->select(["st_x(location::geometry) as lon"]);
Thanks for adding it as test :+1:
There are't errors, just not created lon column.
PostgreSQL PostGIS Query and other ActiveRecord methods don't work for example for Query:: can't return anything when I use functions like st_x, st_y with geometry.. the returned row don't produce column name "lon".
$query = Core::find(); $query->select(new Expression("st_x(location::geometry) as lon"))->where("1=1"); // or $query->select("st_x(location::geometry) as lon")->where("1=1"); $query->all();
This dont emit any answer with lon parameter, but should work...When I use a createCommand with setSql, everythings works fine.. (but it's not good option for the longer queries, that i need to prepare) In this case "lon" is properly returned but it worked only with createCommand method..
Yii::$app->db->createCommand()->setSql('SELECT st_y(location::geometry) as lon FROM core WHERE 1 = 1')->query();
This emit answer with lon parameter computed to for example "4.99212"In db location field has geometry type with value for exampe: 0101000020E610000000000000000008400000000000000840