1#include "duckdb/parser/transformer.hpp"
2#include "duckdb/parser/statement/set_statement.hpp"
3
4namespace duckdb {
5
6unique_ptr<SetStatement> Transformer::TransformUse(duckdb_libpgquery::PGUseStmt &stmt) {
7 auto qualified_name = TransformQualifiedName(root&: *stmt.name);
8 if (!IsInvalidCatalog(str: qualified_name.catalog)) {
9 throw ParserException("Expected \"USE database\" or \"USE database.schema\"");
10 }
11 string name;
12 if (IsInvalidSchema(str: qualified_name.schema)) {
13 name = qualified_name.name;
14 } else {
15 name = qualified_name.schema + "." + qualified_name.name;
16 }
17 return make_uniq<SetVariableStatement>(args: "schema", args: std::move(name), args: SetScope::AUTOMATIC);
18}
19
20} // namespace duckdb
21