Custom views query - pager dosn't work
Ok, I resolved the issue with the hook_views_query_alter using add_where_expression method. It allows you to create complex where conditions. Below is example

// Delete current where conditions created by view and replace it by custom ones.
unset($query-&gt;where);
$query-&gt;add_where_expression(0,'node.type = :node_type', array(':node_type' =&gt; $node_type));
$query-&gt;add_where_expression(0,'node.status = :node_status', array(':node_status' =&gt; $node_status));
$query-&gt;add_where_expression(0,"(CASE node.type WHEN 'event' THEN field_data_field_date_and_time.field_date_and_time_value WHEN 'training_course' THEN field_data_field_date_and_time.field_date_and_time_value ELSE NOW() END) &gt;= NOW()");

$or_conditions = array();

$or_conditions[] = '(og_membership.gid = :public_by_gid)';
$or_conditions[] = '(field_data_field_og_public_to.field_og_public_to_target_id = :public_to_gid)';
$or_conditions[] = '((field_data_field_og_public_to.field_og_public_to_target_id = :public_to_gid) AND (og_membership.gid IS NULL))';

$or_condition = implode(' OR ', $or_conditions);

$query-&gt;add_where_expression(0, $or_condition, array(':public_by_gid' =&gt; $public_by_gid, ':public_to_gid' =&gt; $public_to_gid));


I hope it was useful for someone.