Search code examples
sqlnode.jssql-serverknex.js

Knex: How to trim the result?


When using SQL, the query can be written as:

select RTRIM(dept_id) as dept_id from dept 

Apart from using knex.raw, could we achieve trimming using knex native API?

My SQL Server version is 2000.


Solution

  • We can use knex.raw() as partial query as below instead of changing the whole query in knex.raw()

    knex.select("*", knex.raw(RTrim(dept_id) as dept_id)).from("dept")