{"record":{"id":"2a896256d46becb0","repo":"apache/cassandra","slug":"s-selection-is-only-allowed-on-sets-and-maps-but","errorCode":null,"errorMessage":"%s selection is only allowed on sets and maps, but %s is a list","messagePattern":"(.+?) selection is only allowed on sets and maps, but (.+?) is a list","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/selection/Selectable.java","lineNumber":150,"sourceCode":"        return getExactTypeIfKnown(keyspace);\n    }\n\n    default int addAndGetIndex(ColumnMetadata def, List<ColumnMetadata> l)\n    {\n        int idx = l.indexOf(def);\n        if (idx < 0)\n        {\n            idx = l.size();\n            l.add(def);\n        }\n        return idx;\n    }\n\n    default ColumnSpecification specForElementOrSlice(Selectable selected, ColumnSpecification receiver, CollectionType.Kind kind, String selectionType)\n    {\n        switch (kind)\n        {\n            case LIST: throw new InvalidRequestException(String.format(\"%s selection is only allowed on sets and maps, but %s is a list\", selectionType, selected));\n            case SET: return Sets.valueSpecOf(receiver);\n            case MAP: return Maps.keySpecOf(receiver);\n            default: throw new AssertionError();\n        }\n    }\n\n    public interface Raw\n    {\n        public Selectable prepare(TableMetadata table);\n    }\n\n    public static class WithTerm implements Selectable\n    {\n        /**\n         * The names given to unamed bind markers found in selection. In selection clause, we often don't have a good\n         * name for bind markers, typically if you have:\n         *   SELECT (int)? FROM foo;\n         * there isn't a good name for that marker. So we give the same name to all the markers. Note that we could try","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/selection/Selectable.java#L132-L168","documentation":"Element or slice selection (x[i], x[a..b]) is only defined for sets and maps. CollectionType.Kind LIST is rejected because positional list indexing in the selection clause is not supported, and specForElementOrSlice has no valid receiver spec for a list.","triggerScenarios":"SELECT mylist[0] FROM t — attempting element selection on a column whose type is a frozen/multi-cell list.","commonSituations":"Developers familiar with array indexing try positional access on list columns in SELECT; lists only support indexed update in CQL, not element selection in the projection.","solutions":["Fetch the whole list and index it client-side","Convert the column to a map (e.g. map<int,text>) keyed by index if positional selection is genuinely needed","Use UPDATE ... SET l[i] = x for writes; selection of list elements is unsupported"],"exampleFix":"// before\nSELECT tags[0] FROM t;\n// after\nSELECT tags FROM t; // index client-side","handlingStrategy":"validation","validationCode":"if (columnMetadata.getType() instanceof ListType)\n    throw new IllegalArgumentException(\"element/slice selection not allowed on list column \" + col);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember: [] selection works only on sets and maps","Model indexed lookups with map<key,value> columns instead of lists","Fetch lists whole and index in application code"],"tags":["cql","list","selection"],"backgroundTag":"unsupported-operation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}