1#include "duckdb/parser/statement/create_statement.hpp"
2#include "duckdb/parser/parsed_data/create_table_info.hpp"
3#include "duckdb/parser/tableref/basetableref.hpp"
4#include "duckdb/parser/transformer.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9unique_ptr<CreateStatement> Transformer::TransformCreateTableAs(PGNode *node) {
10 auto stmt = reinterpret_cast<PGCreateTableAsStmt *>(node);
11 assert(stmt);
12 if (stmt->relkind == PG_OBJECT_MATVIEW) {
13 throw NotImplementedException("Materialized view not implemented");
14 }
15 if (stmt->is_select_into || stmt->into->colNames || stmt->into->options) {
16 throw NotImplementedException("Unimplemented features for CREATE TABLE as");
17 }
18 auto tableref = TransformRangeVar(stmt->into->rel);
19 auto query = TransformSelect(stmt->query);
20 auto &basetable = (BaseTableRef &)*tableref;
21
22 auto result = make_unique<CreateStatement>();
23 auto info = make_unique<CreateTableInfo>();
24 info->schema = basetable.schema_name;
25 info->table = basetable.table_name;
26 info->on_conflict = stmt->if_not_exists ? OnCreateConflict::IGNORE : OnCreateConflict::ERROR;
27 info->query = move(query);
28 result->info = move(info);
29 return result;
30}
31