{"id":"25ae7c3a4cbe8190","repo":"drizzle-team/drizzle-orm","slug":"arrayoverlaps-requires-at-least-one-value","errorCode":null,"errorMessage":"arrayOverlaps requires at least one value","messagePattern":"arrayOverlaps requires at least one value","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/sql/expressions/conditions.ts","lineNumber":733,"sourceCode":"export function arrayOverlaps<T>(\n\tcolumn: SQL.Aliased<T>,\n\tvalues: (T | Placeholder) | SQLWrapper,\n): SQL;\nexport function arrayOverlaps<TColumn extends Column>(\n\tcolumn: TColumn,\n\tvalues: (GetColumnData<TColumn, 'raw'> | Placeholder) | SQLWrapper,\n): SQL;\nexport function arrayOverlaps<T extends SQLWrapper>(\n\tcolumn: Exclude<T, SQL.Aliased | Column>,\n\tvalues: (unknown | Placeholder)[] | SQLWrapper,\n): SQL;\nexport function arrayOverlaps(\n\tcolumn: SQLWrapper,\n\tvalues: (unknown | Placeholder)[] | SQLWrapper,\n): SQL {\n\tif (Array.isArray(values)) {\n\t\tif (values.length === 0) {\n\t\t\tthrow new Error('arrayOverlaps requires at least one value');\n\t\t}\n\t\tconst array = sql`${bindIfParam(values, column)}`;\n\t\treturn sql`${column} && ${array}`;\n\t}\n\n\treturn sql`${column} && ${bindIfParam(values, column)}`;\n}\n","sourceCodeStart":715,"sourceCodeEnd":741,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sql/expressions/conditions.ts#L715-L741","documentation":"Thrown by arrayOverlaps() when the values argument is an empty Array. arrayOverlaps emits the '&&' (array-overlap) operator, which is meaningless with no elements to overlap, so drizzle rejects it up front at conditions.ts:732-733.","triggerScenarios":"Calling arrayOverlaps(column, []) or arrayOverlaps(column, computedArray) where computedArray.length === 0. Non-array arguments (SQLWrapper/Placeholder) bypass the check.","commonSituations":"A 'matches any of' tag filter built from an empty UI selection; a recommended-tags list that came back empty from an API; passing an empty array constant by accident when refactoring.","solutions":["Skip the overlaps predicate when the candidate array is empty (no overlap is then the correct result anyway).","Validate the array length at the service layer before reaching the query builder.","Log and bail early if the filter source unexpectedly returned []."],"exampleFix":"// before\n.where(arrayOverlaps(posts.tags, tags)) // throws if tags === []\n\n// after\nconst q = db.select().from(posts);\nif (tags.length) q.where(arrayOverlaps(posts.tags, tags));","handlingStrategy":"validation","validationCode":"function safeArrayOverlaps(column, values) {\n  if (Array.isArray(values) && values.length === 0) return undefined;\n  return arrayOverlaps(column, values);\n}","typeGuard":"const isNonEmptyArray = (v): v is unknown[] => Array.isArray(v) && v.length > 0;","tryCatchPattern":null,"preventionTips":["Skip the overlaps predicate when the candidate list is empty (no overlap is the correct result).","Validate recommendation/feature arrays before use in overlap filters.","Wrap the three array helpers in a project-local safe-wrapper to apply the guard once."],"tags":["validation","postgres-array","query-builder"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}