By default my query is : select * from table
how can i add "where field1={{ txtInput.value }}" when txtInput is not empty ?
Thanks
By default my query is : select * from table
how can i add "where field1={{ txtInput.value }}" when txtInput is not empty ?
Thanks
{{ "select * from table" + (txtInput.value) ? "where field1=" + {{ txtInput.value}} : "" }}
You could also add an OR statement to cover both cases, eg:
where ( {{!txtInput.value}} or field1 = {{ txtInput.value }} )
This might become useful when/if you have multiple where clauses and need to include the word 'where' but does make your query a little longer to read.
If field1 is an integer it return : invalid input syntax for type integer: ""
A way to fix this ?
So that would suggest you're component is returning an empty string instead of I'm guessing that your txtInput component is a text input field and not a number input?
You can use parseInt to convert it to an integer in the case that the user has entered a value into your text input eg {{ parseInt(textInput1.value) }}
but this will only work if they're entered something that can be converted into a number.