latitude-dev / latitude

Developer-first embedded analytics
https://latitude.so
GNU Lesser General Public License v3.0
626 stars 21 forks source link

Concat params in SQL #323

Closed abgonzalez93 closed 3 weeks ago

abgonzalez93 commented 3 weeks ago

Environment

Actual Behaviour

Is there anyway to concat a String with a param variable inside a SQL code? For example, in my case, Im using a LIKE operator, which uses a % inside a string, ie '%something%' So my question is, how can you concat a string with a param(variable) or even {interpolate(param(variable))}

This is my code right now (but its not working tho) imagen

csansoon commented 3 weeks ago

You can concatenate strings before adding it to the query, like this:

desc_agencia LIKE {'%' + param('agency_filter') + '%'}

or interpolate it if you need it:

desc_agencia LIKE \'{interpolate('%' + param('agency_filter') + '%')}\'

Also, you can use variables for improving the query readability:

{#if param('agency_filter', false)}
  {filter = '%' + param('agency_filter') + '%'}
  AND desc_agencia LIKE \'{interpolate(filter)}\'
{/if}
abgonzalez93 commented 3 weeks ago

Yeah, that actually helped. Thanks for your time! It might be interesting if it's put into the website

csansoon commented 3 weeks ago

You're right! I'm working on improving the SQL logic documentation to make it more clear and easy to understand. Thanks for the feedback!