How do I replace the SQL query of a view? I need to override an SQL query of a view. I'm using Drupal 7 and Views 3.x-7.x-alpha1.

I understood I can write my own query with views_pre_execute. I followed the instructions mentioned here: http://blog.raisedeyebrow.com/2010/04/rewrite-a-views-query/.

I added this piece of code to my custom module.

function alterquery_views_pre_execute(&amp;$view) {
  dsm($view);
}


Following the instructions, when I look for the value of $view-&gt;build_info['query'], I see that the type is object of a class SelectQuery.

How am I able to get total control of the query and use my own select statement?
I know that with hook_views_query_alter() I can modify a keyed array, but I would rather write the select statement from scratch.
Well, nothing is stoping you from building your own SelectQuery object and replacing the existing one. Overriding the query plugin is also an option. In this case it would be best to know WHY you're trying to replace the whole query. It makes very little sense to me.

Also, you're using alpha1? Why? That code is four and a half months old. Before attempting anything else, please update to -dev.