Closed fabiog1901 closed 1 year ago
Is this a duplicate of https://github.com/cockroachdb/cockroach/issues/67951? Consider converting the CASE
to an IF
Thanks Andrew, I tried as follows but it still errors out with the same message:
WITH input_cte AS (
SELECT column1 AS aid, column2 AS did, column3 AS amt, column4 AS ttype
FROM (values('A_7', 'A_8', 9, 'DEBIT'))
),
update_acct AS (
UPDATE account_balance
SET runningBalance_am = (
SELECT IF ((runningBalance_am - (SELECT amt FROM input_cte)) > 0, (SELECT runningBalance_am - amt FROM input_cte) , runningBalance_am)
FROM account_balance
WHERE account_id = (SELECT aid FROM input_cte)
)
WHERE account_id = (SELECT aid FROM input_cte)
RETURNING (runningBalance_am)
)
SELECT aid, did, amt, ttype, runningBalance_am, IF ((runningBalance_am - amt) >= 0, '[{"VALID TXN}]', '[{"BOGUS"}]' )
FROM update_acct
FULL OUTER JOIN input_cte ON (1=1)
;
Alright, well I'm out of my depth. Somebody from @cockroachdb/sql-queries will need to have a look.
I'm running into a
ERROR: could not decorrelate subquery
when running the CTE which demonstrate an example on how you can re-write some stored procedures that use variables. These statements used to run up until 20.1, and return said error from 20.2. Where can I start please to rewrite the CTE, please?Jira issue: CRDB-11651