{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/8276","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/8276/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/8276/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/8276/events","html_url":"https://github.com/yiisoft/yii2/issues/8276","id":73183217,"number":8276,"title":"Error with Concat in active record select functions ","user":{"login":"rrhyne","id":539268,"avatar_url":"https://avatars.githubusercontent.com/u/539268?v=3","gravatar_id":"","url":"https://api.github.com/users/rrhyne","html_url":"https://github.com/rrhyne","followers_url":"https://api.github.com/users/rrhyne/followers","following_url":"https://api.github.com/users/rrhyne/following{/other_user}","gists_url":"https://api.github.com/users/rrhyne/gists{/gist_id}","starred_url":"https://api.github.com/users/rrhyne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rrhyne/subscriptions","organizations_url":"https://api.github.com/users/rrhyne/orgs","repos_url":"https://api.github.com/users/rrhyne/repos","events_url":"https://api.github.com/users/rrhyne/events{/privacy}","received_events_url":"https://api.github.com/users/rrhyne/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-05T02:29:40Z","updated_at":"2015-05-10T15:11:31Z","closed_at":"2015-05-05T08:25:59Z","body":"AR parses select calls so that every word in a select query is surrounded by ticks. This breaks the ability to concat() strings with field values. \r\n\r\n    $quotes = Quote::find()->select(\"id, CONCAT(`name`, ' model id: ' ,id) as name\")->all();\r\n\r\nResults in the error:\r\n\r\n<pre>\r\nSQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `quote`' at line 1\r\nThe SQL being executed was: SELECT `id`, CONCAT(`name`, `' model id: '`, `id)` AS `name` FROM `quote`\r\n</pre>\r\n\r\nYou can clearly see the middle value of the concat statement is surrounded by ticks as if it were a field.\r\n\r\nA valid sql query would be:\r\n\r\nselect id, CONCAT(`name`, ' model id: ' ,`id`) as name from quote;\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/100653925","html_url":"https://github.com/yiisoft/yii2/issues/8276#issuecomment-100653925","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/8276","id":100653925,"user":{"login":"rrhyne","id":539268,"avatar_url":"https://avatars.githubusercontent.com/u/539268?v=3","gravatar_id":"","url":"https://api.github.com/users/rrhyne","html_url":"https://github.com/rrhyne","followers_url":"https://api.github.com/users/rrhyne/followers","following_url":"https://api.github.com/users/rrhyne/following{/other_user}","gists_url":"https://api.github.com/users/rrhyne/gists{/gist_id}","starred_url":"https://api.github.com/users/rrhyne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rrhyne/subscriptions","organizations_url":"https://api.github.com/users/rrhyne/orgs","repos_url":"https://api.github.com/users/rrhyne/repos","events_url":"https://api.github.com/users/rrhyne/events{/privacy}","received_events_url":"https://api.github.com/users/rrhyne/received_events","type":"User","site_admin":false},"created_at":"2015-05-10T15:11:31Z","updated_at":"2015-05-10T15:11:31Z","body":"Thanks arisk. In case anyone else finds this issue, this is also a solution, from the documentation: \r\n\r\n\"If you do not call the select() method when building a query, * will be selected, which means selecting all columns.\r\n\r\nBesides column names, you can also select DB expressions. You must use the array format when selecting a DB expression that contains commas to avoid incorrect automatic name quoting. For example:\"\r\n\r\n$query->select([\"CONCAT(first_name, ' ', last_name) AS full_name\", 'email']);"}}