{"record":{"id":"b7749929e6f82f53","repo":"prestodb/presto","slug":"not-supported-b77499","errorCode":"NOT_SUPPORTED","errorMessage":"USE statement is not supported","messagePattern":"USE statement is not supported","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":508,"sourceCode":"        }\n\n        public Scope process(Node node, Optional<Scope> scope)\n        {\n            Scope returnScope = super.process(node, scope);\n            checkState(returnScope.getOuterQueryParent().equals(outerQueryScope), \"result scope should have outer query scope equal with parameter outer query scope\");\n            scope.ifPresent(value -> checkState(hasScopeAsLocalParent(returnScope, value), \"return scope should have context scope as one of ancestors\"));\n            return returnScope;\n        }\n\n        private Scope process(Node node, Scope scope)\n        {\n            return process(node, Optional.of(scope));\n        }\n\n        @Override\n        protected Scope visitUse(Use node, Optional<Scope> scope)\n        {\n            throw new SemanticException(NOT_SUPPORTED, node, \"USE statement is not supported\");\n        }\n\n        @Override\n        protected Scope visitInsert(Insert insert, Optional<Scope> scope)\n        {\n            QualifiedObjectName targetTable = createQualifiedObjectName(session, insert, insert.getTarget(), metadata);\n\n            MetadataHandle metadataHandle = analysis.getMetadataHandle();\n            if (getViewDefinition(session, metadataResolver, metadataHandle, targetTable).isPresent()) {\n                throw new SemanticException(NOT_SUPPORTED, insert, \"Inserting into views is not supported\");\n            }\n\n            if (getMaterializedViewDefinition(session, metadataResolver, metadataHandle, targetTable).isPresent()) {\n                throw new SemanticException(NOT_SUPPORTED, insert, \"Inserting into materialized views is not supported\");\n            }\n\n            // analyze the query that creates the data\n            Scope queryScope = process(insert.getQuery(), scope);","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L490-L526","documentation":"Presto does not implement the SQL USE statement (e.g. USE catalog.schema or USE schema). During semantic analysis, StatementAnalyzer.visitUse unconditionally throws a SemanticException with code NOT_SUPPORTED, because query session/catalog/schema selection in Presto is done at the connection/session level, not via SQL statements. The statement is rejected before any further analysis.","triggerScenarios":"Executing a 'USE <schema>' or 'USE <catalog>.<<schema>' statement through Presto (via JDBC execute, CLI, or any client submitting a Use node). StatementAnalyzer.visitUse always throws — there is no condition under which USE succeeds.","commonSituations":"Migrating SQL scripts from MySQL, SQL Server, Hive CLI, or Spark where 'USE db' sets the default database; BI tools or ORM generators that emit USE before queries; copy-pasted legacy ETL scripts run against Presto.","solutions":["Remove the USE statement and fully qualify table names (catalog.schema.table) in queries.","Set the default catalog/schema on the session instead: JDBC URL parameter '?catalog=X&schema=Y' or SET SESSION equivalent via the client connection properties.","If using the Presto CLI, pass --catalog and --schema flags at launch instead of issuing USE.","If migrating a script generator, configure it to not emit USE for Presto targets."],"exampleFix":"// before\nStatement stmt = conn.createStatement();\nstmt.execute(\"USE sales.europe\");\nstmt.execute(\"SELECT * FROM orders\");\n\n// after\n// connect with jdbc:presto://host:8080/sales/europe\nStatement stmt = conn.createStatement();\nstmt.execute(\"SELECT * FROM sales.europe.orders\");","handlingStrategy":"validation","validationCode":"if (sql.trim().toUpperCase().startsWith(\"USE \")) {\n    throw new IllegalArgumentException(\"Presto does not support USE; set catalog/schema on the connection instead\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never emit USE statements in SQL targeting Presto; strip them in any script preprocessor.","Set default catalog/schema via JDBC URL (jdbc:presto://host:port/catalog/schema) or CLI --catalog/--schema flags.","Fully qualify table references (catalog.schema.table) in generated SQL."],"tags":["sql","not-supported","presto","semantic-analysis"],"backgroundTag":"use-statement-not-supported","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}