-11

We are not able to run a query like the following in SEDE:

select avg(viewCount) from Posts

It is giving us an arithmetic exception which should ideally not be the case.

All we need to do is change the column datatype to double.

6
  • 3
    Are you talking about the Data Explorer? – ale Aug 28 '17 at 13:14
  • how about: select avg(Cast(viewCount) as Float) from Posts – bummi Aug 28 '17 at 13:22
  • 6
    It's already been asked by the same OP and answered on Meta.SO: meta.stackoverflow.com/questions/355679/… – PeterJ Aug 28 '17 at 13:23
  • This is not in any way a bug. You can't expect to add up the views from every single question in the database and not exceed INT_MAX. Your query needs updated, not our database tables. – animuson Aug 28 '17 at 15:28
  • It is worth trying to have you fix my bugs @animuson ... ;) – rene Aug 28 '17 at 15:49
  • All we need to do is change the column datatype to double. Looking at the available datatypes there is no double so your proposed fix will not work. – rene Aug 29 '17 at 7:28
6

All we need to do is change the column datatype to double.

No. You are not going to change the data type of a column to accommodate any function you can call on it. The view count is an integral number. Just keep it that way.

You've asked the same question on MSO already, and the solution there is the best available option, and that is casting it yourself:

select avg(CAST(viewcount as float)) as average from posts

(Credits to Makoto, who proposed this solution)

1
  • 2
    cast to bigint will work as well and maybe preferable over a float. – rene Aug 28 '17 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .