errorQuery failed: Cannot cast '2' to BOOLEAN in below query -SELECT Account.id as…
- User
errorQuery failed: Cannot cast '2' to BOOLEAN in below query -SELECT Account.id as "AccountID", Account.name, Account.accountnumber, Account.batch, Account.additionalemailaddresses, contact.firstname, contact.lastname, contact.workemail, contact.personalemail, Invoice.amount, Invoice.balance, Invoice.duedate, Invoice.invoicedate, Invoice.invoicenumber, Invoice.status, Invoice.id, date_diff('day', Invoice.duedate, current_date) as "duedays", Subscription.id as "SubscriptionID", Subscription.name, Subscription.status FROM InvoiceItem IT JOIN Account on IT.accountid = Account.id JOIN Invoice on IT.invoiceid = Invoice.id JOIN contact on contact.id = Account.BillToId JOIN Subscription on IT.subscriptionid = Subscription.id WHERE (date_diff('day', Invoice.duedate, current_date) = CAST(CAST('{{Data.Workflow.a}}' AS BOOLEAN) AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST(CAST('{{Data.Workflow.b}}' AS BOOLEAN) AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST(CAST('{{Data.Workflow.c}}' AS BOOLEAN) AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST(CAST('{{Data.Workflow.d}}' AS BOOLEAN) AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST(CAST('{{Data.Workflow.e}}' AS BOOLEAN) AS BIGINT)) AND Invoice.balance>0 AND Invoice.status = 'Posted'
- Assistant
The error occurs because the CAST function is trying to cast a string (e.g. 'true' or 'false') to a BOOLEAN, but the string value cannot be casted to BOOLEAN.
To fix the issue, ensure that the input value for the CAST function is either a valid BOOLEAN value (e.g. true or false) or a valid number that can be casted to BIGINT. In the current query, it is unclear what the input value for the CAST function should be, as it is referencing workflow variables that are not defined in the query.
- User
correct the sql syntax - (date_diff(‘day’, Invoice.duedate, current_date) = CAST(CAST(‘{{Data.Workflow.a}}’ AS BOOLEAN) AS BIGINT)
- Assistant
Assuming that the input value for the CAST function should be a string that can be parsed as a BOOLEAN (e.g. 'true' or 'false'), you can correct the syntax of the query by removing the outer CAST function and directly casting the string to a BOOLEAN. The corrected query would look like this:
SELECT Account.id AS "AccountID", Account.name, Account.accountnumber, Account.batch, Account.additionalemailaddresses, contact.firstname, contact.lastname, contact.workemail, contact.personalemail, Invoice.amount, Invoice.balance, Invoice.duedate, Invoice.invoicedate, Invoice.invoicenumber, Invoice.status, Invoice.id, date_diff('day', Invoice.duedate, current_date) AS "duedays", Subscription.id AS "SubscriptionID", Subscription.name, Subscription.status FROM InvoiceItem IT JOIN Account ON IT.accountid = Account.id JOIN Invoice ON IT.invoiceid = Invoice.id JOIN contact ON contact.id = Account.BillToId JOIN Subscription ON IT.subscriptionid = Subscription.id WHERE ( date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.a}}' AS BOOLEAN) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.b}}' AS BOOLEAN) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.c}}' AS BOOLEAN) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.d}}' AS BOOLEAN) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.e}}' AS BOOLEAN) ) AND Invoice.balance > 0 AND Invoice.status = 'Posted' - User
Cast this syntaxto big integer -date_diff(‘day’, Invoice.duedate, current_date) = ‘{{Data.Workflow.d}}’
- Assistant
To cast the string
'{{Data.Workflow.d}}'to a BIGINT, you can use the following CAST function syntax:CAST('{{Data.Workflow.d}}' AS BIGINT)Assuming you want to use this syntax to replace the string value in the original query, you can modify the query as follows:
SELECT Account.id AS "AccountID", Account.name, Account.accountnumber, Account.batch, Account.additionalemailaddresses, contact.firstname, contact.lastname, contact.workemail, contact.personalemail, Invoice.amount, Invoice.balance, Invoice.duedate, Invoice.invoicedate, Invoice.invoicenumber, Invoice.status, Invoice.id, date_diff('day', Invoice.duedate, current_date) AS "duedays", Subscription.id AS "SubscriptionID", Subscription.name, Subscription.status FROM InvoiceItem IT JOIN Account ON IT.accountid = Account.id JOIN Invoice ON IT.invoiceid = Invoice.id JOIN contact ON contact.id = Account.BillToId JOIN Subscription ON IT.subscriptionid = Subscription.id WHERE ( date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.a}}' AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.b}}' AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.c}}' AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.d}}' AS BIGINT) OR date_diff('day', Invoice.duedate, current_date) = CAST('{{Data.Workflow.e}}' AS BIGINT) ) AND Invoice.balance > 0 AND Invoice.status = 'Posted'