Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Views Raw SQL

Security covered Under active development 474 sites

Part of the Views ecosystem · 286 projects

This module allows you to add custom SQL expressions to your Views for fields and sorting. It's useful for complex calculations that go beyond what standard Views or other modules can handle, but should be used with caution due to potential security risks.

Views Raw SQL allows arbitrary SQL expressions to be added to Views, as fields and sorts. This is useful when you want to do something more complicated than Views or Views Calc can do already, e.g. sort by the sum of two fields multiplied by the square root of another field, and you've already built functionality around doing this in Views so it would be a pain to switch to a custom query.

IMPORTANT: Views Raw SQL expressions are not safe by design!. They can be used to circumvent data access restrictions with malicious SQL or to break a view with invalid SQL. So be very careful who you grant permission to use this module! Only use it, if you really need it and know what you're doing!

A typical use of this module will look something like this:

  1. In Views configuration, turn on the option to display query in preview.
  2. Create a View that includes all of the fields you want to use in your SQL expressions. For example, if you want to add two number fields together, you first need to get the number fields loading. If you don't know how to do this, you shouldn't be using this module.
  3. In the query preview, find the names of the fields you want to use. If you don't know how to read a SQL query, you shouldn't be using this module.
  4. Add a new raw SQL field or sort, and write an expression that uses existing fields.

In the example, above, the raw SQL field looked like this:

(field_data_field_value_change_week.field_value_change_week_value / field_data_field_value.field_value_value) * SQRT(field_data_field_value.field_value_value)

Alternative modules:

https://www.drupal.org/project/views_date_format_sql - to use SQL for date formatting (to allow aggregation / grouping)

Ask your assistant about Views Raw SQL

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Sep 2024
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
2.0.0-alpha1 Pre-release 10–11 Sep 9, 2024
2.x-dev Dev 10–11 Sep 6, 2024