MariaDb does not support ANY_VALUE() function

我与影子孤独终老i 提交于 2020-06-28 18:01:17

问题


I have a laravel project which is connected to mysql db, when I change my server, my codes got failed because my new server has a Mariadb, when I checked my logs, I have realised that, there is some unsupported function from MariaDb which is ANY_VALUE(),

how can I edit my sql according to MariaDb ?

select(DB::raw('SUM(price) as price, SUM(price_now) as price_now, 
   ANY_VALUE(price_available) as price_available'),'adult_count')

error log


回答1:


For today, you have solved the problem. But tomorrow, when you run the same query, you will get a different error.

In older versions of MySQL or MariaDB, you would get "any value" for price_available when not GROUPing BY it. That was effectively somewhere between "bad practice" and a "standards violation". Relatively recently, MariaDB, then later MySQL, switched to "only full group by". At that time, ANY_VALUE() came into existence for MySQL, but apparently MariaDB dropped the ball.

The old workaround, which should be safe for both old and new versions is to use MIN(price_available) or some other aggregate function.

See also the ONLY_FULL_GROUP_BY setting.




回答2:


I have solved with replacing this:

select(DB::raw('SUM(price) as price, SUM(price_now) as price_now, ANY_VALUE(price_available) as price_available'),'adult_count')

to

select(DB::raw('SUM(price) as price, SUM(price_now) as price_now, price_available as price_available'),'adult_count')



来源:https://stackoverflow.com/questions/54167995/mariadb-does-not-support-any-value-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!