You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from unnest(coalesce(nullif(v_channel_types, '{}'), enum_range(null::public.channel_type))) channel_type
184
+
);
185
+
-- we need to include columns we filter on top-level
186
+
v_include_subqueries text[];
187
+
v_exclude_subqueries text[];
188
+
v_where_clauses text[];
189
+
begin
190
+
if cardinality(v_columns) = 0 and v_count_only is not true then
191
+
raise exception using
192
+
message = 'No columns provided',
193
+
hint = 'Please pass v_columns',
194
+
errcode = 'INVIN';
195
+
end if;
196
+
197
+
if v_order_by is not null and v_limit is null then
198
+
raise exception using
199
+
message = 'v_order_by is only allowed if v_limit is set',
200
+
hint = 'Please pass v_limit',
201
+
errcode = 'INVIN';
202
+
end if;
203
+
204
+
if v_limit is not null and v_limit > 50 then
205
+
raise exception using
206
+
message = 'v_limit is too high',
207
+
hint = 'Please pass a v_limit of 50 or lower',
208
+
errcode = 'INVIN';
209
+
end if;
210
+
211
+
v_where_clauses := array_remove(
212
+
array[
213
+
-- is_blocked filter
214
+
(case when v_include_blocked is true then null else 'is_blocked is not true' end),
215
+
-- opt in filter
216
+
(
217
+
case
218
+
when v_require_marketing_opt_in is true then
219
+
'(' || (select string_agg(format('(%s is not null and %s_marketing_opt_in is true)', ct.type, ct.type), ' or ') from unnest(coalesce(v_channel_types, enum_range(null::public.channel_type))) ct(type)) || ')'
220
+
when v_require_transactional_opt_in is true then
221
+
'(' || (select string_agg(format('(%s is not null and %s_transactional_opt_in is not null)', channel_type, channel_type), ' or ') from unnest(coalesce(v_channel_types, enum_range(null::public.channel_type))) channel_type) || ')'
222
+
when v_channel_types is not null and cardinality(v_channel_types) > 0 then
223
+
'(' || (select string_agg(format('(%s is not null)', channel_type), ' or ') from unnest(v_channel_types) channel_type) || ')'
0 commit comments