{"record":{"id":"164f0a81e2881638","repo":"apache/cassandra","slug":"not-in-any-keyspace","errorCode":null,"errorMessage":"Not in any keyspace.","messagePattern":"Not in any keyspace\\.","errorType":"exception","errorClass":"NoKeyspaceError","httpStatus":null,"severity":"error","filePath":"pylib/cqlshlib/cqlshmain.py","lineNumber":1420,"sourceCode":"          PAGETIMEOUT=10           - the page timeout in seconds for fetching results\n          BEGINTOKEN=''            - the minimum token string to consider when exporting data\n          ENDTOKEN=''              - the maximum token string to consider when exporting data\n          MAXREQUESTS=6            - the maximum number of requests each worker process can work on in parallel\n          MAXOUTPUTSIZE='-1'       - the maximum size of the output file measured in number of lines,\n                                     beyond this maximum the output file will be split into segments,\n                                     -1 means unlimited.\n          FLOATPRECISION=5         - the number of digits displayed after the decimal point for cql float values\n          DOUBLEPRECISION=12       - the number of digits displayed after the decimal point for cql double values\n\n        When entering CSV data on STDIN, you can use the sequence \"\\.\"\n        on a line by itself to end the data input.\n        \"\"\"\n\n        ks = self.cql_unprotect_name(parsed.get_binding('ksname', None))\n        if ks is None:\n            ks = self.current_keyspace\n            if ks is None:\n                raise NoKeyspaceError(\"Not in any keyspace.\")\n        table = self.cql_unprotect_name(parsed.get_binding('cfname'))\n        columns = parsed.get_binding('colnames', None)\n        if columns is not None:\n            columns = list(map(self.cql_unprotect_name, columns))\n        else:\n            # default to all known columns\n            columns = self.get_column_names(ks, table)\n\n        fname = parsed.get_binding('fname', None)\n        if fname is not None:\n            fname = self.cql_unprotect_value(fname)\n\n        copyoptnames = list(map(str.lower, parsed.get_binding('optnames', ())))\n        copyoptvals = list(map(self.cql_unprotect_value, parsed.get_binding('optvals', ())))\n        opts = dict(list(zip(copyoptnames, copyoptvals)))\n\n        direction = parsed.get_binding('dir').upper()\n        if direction == 'FROM':","sourceCodeStart":1402,"sourceCodeEnd":1438,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/pylib/cqlshlib/cqlshmain.py#L1402-L1438","documentation":"The COPY command (do_copy) requires a target keyspace: it uses the keyspace from the COPY statement or the session's current keyspace. If neither exists (no USE was issued and COPY did not specify one), it raises NoKeyspaceError('Not in any keyspace.').","triggerScenarios":"Running COPY <table> TO/FROM without a 'COPY ks.table' qualification while the session has no current keyspace (no USE executed, or the keyspace was dropped clearing context).","commonSituations":"Fresh cqlsh session where the user immediately runs COPY without USE; scripts copied from examples that omit the keyspace; session whose keyspace was dropped by another client.","solutions":["Qualify the table in the COPY statement: COPY ks.table TO 'file.csv'.","Run USE <keyspace> before issuing COPY.","Fix scripts to always set a keyspace at session start.","If the keyspace was dropped, recreate it or point the session at a valid one."],"exampleFix":"// before\nCOPY users TO 'users.csv';  -- NoKeyspaceError (no USE issued)\n// after\nUSE my_ks;\nCOPY users TO 'users.csv';\n// or\nCOPY my_ks.users TO 'users.csv';","handlingStrategy":"validation","validationCode":"if parsed.get_binding('ksname') is None and shell.current_keyspace is None:\n    raise ValueError(\"COPY requires a keyspace: USE one or qualify ks.table\")","typeGuard":"def copy_has_keyspace(shell, ksname_binding):\n    return ksname_binding is not None or shell.current_keyspace is not None","tryCatchPattern":"try:\n    shell.do_copy(statement)\nexcept NoKeyspaceError:\n    # prompt: run USE <keyspace> or qualify COPY ks.table\n    pass","preventionTips":["Always qualify COPY as ks.table in scripts.","Start sessions with an explicit USE statement.","Remember DROP KEYSPACE clears the session's current keyspace context."],"tags":["cassandra","cqlsh","copy","keyspace","session-state"],"backgroundTag":"missing-required-argument","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"}