PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'h0c...' for key 'PRIMARY': UPDATE {sessions}

Started session for anonymous user in mixed mode cause PDOException when user tries to log in. PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'h0c...' for key 'PRIMARY': UPDATE {sessions}

Cleaning huge Drupal 7 DB dump

Sometimes there could be an issue with huge DB which was created not with backup_migrate module but raw mysqldump command. The size of the DB could be over 2GB. Most of the data of this dump are cache tables and logs. Editing this file is not a good choice.

Current solution will remove INSERTS from the file. sed command come in handy here:

Views filter by int value in float field

Imagine, that you have float field with 2 symbols after dot.
At the views page with filter you need to filter values by all range of module of user's float input.
Ex: user input 2.45, we filter all values  X>=2 AND X<(2+1)

With the standard accessories of views you can filter with two filter “from” and “to”. But in FO we have only one field.
To solve this problem we can use hook_views_query_alter.

We already have a view. To make our hook work, we must set the unique tag to the view, to check it in out hook. mymodule_query in example code.