Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Views Raw SQL

Security covered

Part of the Views ecosystem · 211 projects

View on drupal.org

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. 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.

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)

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 Release date
2.0.0-alpha1 Pre-release 10–11 Sep 9, 2024
2.x-dev Dev 10–11 Sep 6, 2024