Raw expressions are the qb escape hatch. While qb strives to provide ways to execute the majority of queries, you will occasionally need to provide raw sql values that are not processed by qb. These SQL snippets are called
Expressions in qb.
The first way to retrieve an
Expression is to call the
raw method on the
The raw sql to wrap up in an Expression.
The sql snippet passed to
raw is not processed by qb at all. With that in mind, it is important to follow all best practices and security recommendations with the sql you use with
QueryBuilderquery.from( "users" ).select( query.raw( "MAX(created_date)" ) );
MySQLSELECT MAX(created_date) FROM `users`
Expressions can be passed to most qb methods, like
orderBy, among others. Additionally, qb provides some convenience methods to add raw values in different parts of the query: