Getting "The column index is out of range" error when adding WHERE clause with Text Variable

The CONCAT solution is totally hacky but totally worked. Thanks for the suggestion!
Below is the code I ended up using for Text Variable + Wildcard search...

select *
from crosstab (
concat(
'select array[component, version]::text[], customer, master_local_family, local_family, int_month, SUM(component_requirement)
from tbl_monthly_ctb_demand
[[WHERE UPPER(customer) LIKE UPPER( ', '''%',{{customer_var}},'%''',
')]] group by component, version, int_month, customer, master_local_family, local_family
ORDER BY 1'),
'values (''202001''),(''202002''),(''202003''),(''202004''),
(''202005''),(''202006''),(''202007''),(''202008''),(''202009''),
(''202010''),(''202011''),(''202012''),(''202101''),(''202102''),(''202103'')
,(''202104''),(''202105''),(''202106''),(''202107''),(''202108''),(''202109'')
,(''202110''),(''202111''),(''202112''),(''202201''),(''202202''),(''202203'')
,(''202204''),(''202205''),(''202206''),(''202207''),(''202208''),(''202209'')
,(''202210''),(''202211''),(''202212'')')
AS ct(
row_id text[],
customer text,
master_local_family text,
local_family text,
Jan20 numeric(12,3),
Feb20 numeric(12,3),
Mar20 numeric(12,3),
Apr20 numeric(12,3),
May20 numeric(12,3),
Jun20 numeric(12,3),
Jul20 numeric(12,3),
Aug20 numeric(12,3),
Sep20 numeric(12,3),
Oct20 numeric(12,3),
Nov20 numeric(12,3),
Dec20 numeric(12,3),
Jan21 numeric(12,3),
Feb21 numeric(12,3),
Mar21 numeric(12,3),
Apr21 numeric(12,3),
May21 numeric(12,3),
Jun21 numeric(12,3),
Jul21 numeric(12,3),
Aug21 numeric(12,3),
Sep21 numeric(12,3),
Oct21 numeric(12,3),
Nov21 numeric(12,3),
Dec21 numeric(12,3),
Jan22 numeric(12,3),
Feb22 numeric(12,3),
Mar22 numeric(12,3),
Apr22 numeric(12,3),
May22 numeric(12,3),
Jun22 numeric(12,3),
Jul22 numeric(12,3),
Aug22 numeric(12,3),
Sep22 numeric(12,3),
Oct22 numeric(12,3),
Nov22 numeric(12,3),
Dec22 numeric(12,3)
);

1 Like