planetarydev/json-sql-builder2

Using cast function in WHERE clause

planetarydev opened this issue · 3 comments

i want to cast any column type while using it in
where.

E.g.
Select * from table1
Where cast(date) = '2019-09-01'

@umer-mehmood You can use the $anyExpr helper or the short-hand simply $.
But you need th write the cast helper at first.

sql.build({
  $select: {
    $from: 'people',
    $where: {
      $and: [
        { $: { $cast: '~~my_date_column', $eq: 10 } }
      ]
    }
  }
});

I though it was not so intuitiv. baut it works. Did you have any idea to implement some other logic for this?

Yes, I have added a CAST helper and using the $anyExpr / $ operator i am able to use a function in where clause.

Thanks!