Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions scripts/parser/grammar_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ ColumnElements:
by_value: true
rules:
- CreateTableColumnList
- CreateTableColumns

CreateTableDefinition:
type: "CreateTableDefinition"
Expand Down Expand Up @@ -1183,6 +1184,7 @@ Bool:
- AnalyzeVerbose
- CheckpointForce
- IfNotExists
- ExternalTable
- OrReplace
- InstallAndLoad
- ShowAllModifier
Expand Down Expand Up @@ -1713,6 +1715,7 @@ IdentifierType:
- AttachAlias
- CollationName
- IndexType
- TableType
- RelOptionName
- TableQualification
- ReservedTableQualification
Expand Down
9 changes: 9 additions & 0 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,15 @@ optional_ptr<DependencyManager> Catalog::GetDependencyManager() {

ErrorData Catalog::SupportsCreateTable(BoundCreateTableInfo &info) {
auto &base = info.Base().Cast<CreateTableInfo>();
if (!base.table_type.empty()) {
return ErrorData(ExceptionType::CATALOG,
StringUtil::Format("Table type %s is not supported for tables in a %s catalog",
base.table_type, GetCatalogType()));
}
if (base.external) {
return ErrorData(ExceptionType::CATALOG,
StringUtil::Format("EXTERNAL is not supported for tables in a %s catalog", GetCatalogType()));
}
if (!base.partition_keys.empty()) {
return ErrorData(
ExceptionType::CATALOG,
Expand Down
10 changes: 10 additions & 0 deletions src/catalog/duck_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "duckdb/parser/parsed_data/drop_info.hpp"
#include "duckdb/parser/parsed_data/alter_schema_info.hpp"
#include "duckdb/parser/parsed_data/create_schema_info.hpp"
#include "duckdb/parser/parsed_data/create_table_info.hpp"
#include "duckdb/planner/parsed_data/bound_create_table_info.hpp"
#include "duckdb/catalog/default/default_schemas.hpp"
#include "duckdb/function/built_in_functions.hpp"
#include "duckdb/main/attached_database.hpp"
Expand Down Expand Up @@ -139,6 +141,14 @@ optional_ptr<CatalogEntry> DuckCatalog::CreateSchema(CatalogTransaction transact
return result;
}

ErrorData DuckCatalog::SupportsCreateTable(BoundCreateTableInfo &info) {
auto &base = info.Base().Cast<CreateTableInfo>();
if (base.external && base.table_type.empty()) {
return ErrorData(ExceptionType::CATALOG, "DuckDB tables cannot be EXTERNAL");
}
return Catalog::SupportsCreateTable(info);
}

void DuckCatalog::DropSchema(CatalogTransaction transaction, DropInfo &info) {
auto &path = info.GetQualifiedName().Path();
auto &schema_name = info.GetQualifiedName().Name();
Expand Down
1 change: 1 addition & 0 deletions src/include/duckdb/catalog/duck_catalog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class DuckCatalog : public Catalog {
const EntryLookupInfo &schema_lookup,
OnEntryNotFound if_not_found) override;

DUCKDB_API ErrorData SupportsCreateTable(BoundCreateTableInfo &info) override;
DUCKDB_API PhysicalOperator &PlanCreateTableAs(ClientContext &context, PhysicalPlanGenerator &planner,
LogicalCreateTable &op, PhysicalOperator &plan) override;
DUCKDB_API PhysicalOperator &PlanInsert(ClientContext &context, PhysicalPlanGenerator &planner, LogicalInsert &op,
Expand Down
4 changes: 4 additions & 0 deletions src/include/duckdb/parser/parsed_data/create_table_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ struct CreateTableInfo : public CreateInfo {
vector<unique_ptr<ParsedExpression>> sort_keys;
//! Extra Table options if any
case_insensitive_map_t<unique_ptr<ParsedExpression>> options;
//! Table type (e.g. ICEBERG), empty for a table of the catalog's default type
string table_type;
//! Whether the table is EXTERNAL, i.e. the catalog references the table but does not manage it
bool external = false;

public:
DUCKDB_API unique_ptr<CreateInfo> Copy() const override;
Expand Down
7 changes: 5 additions & 2 deletions src/include/duckdb/parser/peg/inlined_grammar.gram
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,9 @@ Persistent <- 'PERSISTENT'
TempPersistent <- 'TEMP'
TemporaryPersistent <- 'TEMPORARY'

CreateTableStmt <- 'TABLE' IfNotExists? QualifiedName CreateTableDefinition CommitAction?
CreateTableStmt <- ExternalTable? TableType? 'TABLE' IfNotExists? QualifiedName CreateTableDefinition CommitAction?
ExternalTable <- 'EXTERNAL'
TableType <- Identifier
CreateTableDefinition <- CreateTableAs / CreateColumnList

CreateTableAs <- IdentifierList? PartitionSortedOptions? WithList? 'AS' Statement WithData?
Expand All @@ -986,7 +988,8 @@ WithData <- WithDataOnly / WithNoData
WithDataOnly <- 'WITH' 'DATA'
WithNoData <- 'WITH' 'NO' 'DATA'
IdentifierList <- Parens(List(Identifier))
CreateColumnList <- Parens(CreateTableColumnList?) PartitionSortedOptions? WithList?
CreateColumnList <- CreateTableColumns? PartitionSortedOptions? WithList?
CreateTableColumns <- Parens(CreateTableColumnList?)
IfNotExists <- 'IF' 'NOT' 'EXISTS'
QualifiedName <- CatalogReservedSchemaIdentifier / SchemaReservedIdentifierOrStringLiteral / IdentifierOrStringLiteral
SchemaReservedIdentifierOrStringLiteral <- SchemaQualification ReservedIdentifierOrStringLiteral
Expand Down
86 changes: 46 additions & 40 deletions src/include/duckdb/parser/peg/inlined_grammar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,46 +1116,52 @@ const unsigned char INLINED_PEG_GRAMMAR[] = {
105, 115, 116, 101, 110, 116, 32, 60, 45, 32, 39, 84, 69, 77, 80, 39, 10, 84, 101, 109,
112, 111, 114, 97, 114, 121, 80, 101, 114, 115, 105, 115, 116, 101, 110, 116, 32, 60, 45, 32,
39, 84, 69, 77, 80, 79, 82, 65, 82, 89, 39, 10, 67, 114, 101, 97, 116, 101, 84, 97,
98, 108, 101, 83, 116, 109, 116, 32, 60, 45, 32, 39, 84, 65, 66, 76, 69, 39, 32, 73,
102, 78, 111, 116, 69, 120, 105, 115, 116, 115, 63, 32, 81, 117, 97, 108, 105, 102, 105, 101,
100, 78, 97, 109, 101, 32, 67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 68, 101, 102,
105, 110, 105, 116, 105, 111, 110, 32, 67, 111, 109, 109, 105, 116, 65, 99, 116, 105, 111, 110,
63, 10, 67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 68, 101, 102, 105, 110, 105, 116,
105, 111, 110, 32, 60, 45, 32, 67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 65, 115,
32, 47, 32, 67, 114, 101, 97, 116, 101, 67, 111, 108, 117, 109, 110, 76, 105, 115, 116, 10,
67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 65, 115, 32, 60, 45, 32, 73, 100, 101,
110, 116, 105, 102, 105, 101, 114, 76, 105, 115, 116, 63, 32, 80, 97, 114, 116, 105, 116, 105,
111, 110, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 63, 32, 87, 105, 116,
104, 76, 105, 115, 116, 63, 32, 39, 65, 83, 39, 32, 83, 116, 97, 116, 101, 109, 101, 110,
116, 32, 87, 105, 116, 104, 68, 97, 116, 97, 63, 10, 80, 97, 114, 116, 105, 116, 105, 111,
110, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 80, 97,
114, 116, 105, 116, 105, 111, 110, 79, 112, 116, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105,
111, 110, 115, 32, 47, 32, 83, 111, 114, 116, 101, 100, 79, 112, 116, 80, 97, 114, 116, 105,
116, 105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 10, 80, 97, 114, 116, 105, 116, 105, 111,
110, 79, 112, 116, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45,
32, 80, 97, 114, 116, 105, 116, 105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 32, 83, 111,
114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 63, 10, 83, 111, 114, 116, 101, 100, 79,
112, 116, 80, 97, 114, 116, 105, 116, 105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 32, 60,
45, 32, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 80, 97, 114, 116,
105, 116, 105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 63, 10, 80, 97, 114, 116, 105, 116,
105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 39, 80, 65, 82, 84, 73,
84, 73, 79, 78, 69, 68, 39, 32, 39, 66, 89, 39, 32, 80, 97, 114, 101, 110, 115, 40,
76, 105, 115, 116, 40, 69, 120, 112, 114, 101, 115, 115, 105, 111, 110, 41, 41, 10, 83, 111,
114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 39, 83, 79, 82, 84,
69, 68, 39, 32, 39, 66, 89, 39, 32, 80, 97, 114, 101, 110, 115, 40, 76, 105, 115, 116,
40, 69, 120, 112, 114, 101, 115, 115, 105, 111, 110, 41, 41, 10, 87, 105, 116, 104, 68, 97,
116, 97, 32, 60, 45, 32, 87, 105, 116, 104, 68, 97, 116, 97, 79, 110, 108, 121, 32, 47,
32, 87, 105, 116, 104, 78, 111, 68, 97, 116, 97, 10, 87, 105, 116, 104, 68, 97, 116, 97,
79, 110, 108, 121, 32, 60, 45, 32, 39, 87, 73, 84, 72, 39, 32, 39, 68, 65, 84, 65,
39, 10, 87, 105, 116, 104, 78, 111, 68, 97, 116, 97, 32, 60, 45, 32, 39, 87, 73, 84,
72, 39, 32, 39, 78, 79, 39, 32, 39, 68, 65, 84, 65, 39, 10, 73, 100, 101, 110, 116,
105, 102, 105, 101, 114, 76, 105, 115, 116, 32, 60, 45, 32, 80, 97, 114, 101, 110, 115, 40,
76, 105, 115, 116, 40, 73, 100, 101, 110, 116, 105, 102, 105, 101, 114, 41, 41, 10, 67, 114,
101, 97, 116, 101, 67, 111, 108, 117, 109, 110, 76, 105, 115, 116, 32, 60, 45, 32, 80, 97,
114, 101, 110, 115, 40, 67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 67, 111, 108, 117,
109, 110, 76, 105, 115, 116, 63, 41, 32, 80, 97, 114, 116, 105, 116, 105, 111, 110, 83, 111,
114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 63, 32, 87, 105, 116, 104, 76, 105, 115,
116, 63, 10, 73, 102, 78, 111, 116, 69, 120, 105, 115, 116, 115, 32, 60, 45, 32, 39, 73,
98, 108, 101, 83, 116, 109, 116, 32, 60, 45, 32, 69, 120, 116, 101, 114, 110, 97, 108, 84,
97, 98, 108, 101, 63, 32, 84, 97, 98, 108, 101, 84, 121, 112, 101, 63, 32, 39, 84, 65,
66, 76, 69, 39, 32, 73, 102, 78, 111, 116, 69, 120, 105, 115, 116, 115, 63, 32, 81, 117,
97, 108, 105, 102, 105, 101, 100, 78, 97, 109, 101, 32, 67, 114, 101, 97, 116, 101, 84, 97,
98, 108, 101, 68, 101, 102, 105, 110, 105, 116, 105, 111, 110, 32, 67, 111, 109, 109, 105, 116,
65, 99, 116, 105, 111, 110, 63, 10, 69, 120, 116, 101, 114, 110, 97, 108, 84, 97, 98, 108,
101, 32, 60, 45, 32, 39, 69, 88, 84, 69, 82, 78, 65, 76, 39, 10, 84, 97, 98, 108,
101, 84, 121, 112, 101, 32, 60, 45, 32, 73, 100, 101, 110, 116, 105, 102, 105, 101, 114, 10,
67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 68, 101, 102, 105, 110, 105, 116, 105, 111,
110, 32, 60, 45, 32, 67, 114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 65, 115, 32, 47,
32, 67, 114, 101, 97, 116, 101, 67, 111, 108, 117, 109, 110, 76, 105, 115, 116, 10, 67, 114,
101, 97, 116, 101, 84, 97, 98, 108, 101, 65, 115, 32, 60, 45, 32, 73, 100, 101, 110, 116,
105, 102, 105, 101, 114, 76, 105, 115, 116, 63, 32, 80, 97, 114, 116, 105, 116, 105, 111, 110,
83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 63, 32, 87, 105, 116, 104, 76,
105, 115, 116, 63, 32, 39, 65, 83, 39, 32, 83, 116, 97, 116, 101, 109, 101, 110, 116, 32,
87, 105, 116, 104, 68, 97, 116, 97, 63, 10, 80, 97, 114, 116, 105, 116, 105, 111, 110, 83,
111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 80, 97, 114, 116,
105, 116, 105, 111, 110, 79, 112, 116, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110,
115, 32, 47, 32, 83, 111, 114, 116, 101, 100, 79, 112, 116, 80, 97, 114, 116, 105, 116, 105,
111, 110, 79, 112, 116, 105, 111, 110, 115, 10, 80, 97, 114, 116, 105, 116, 105, 111, 110, 79,
112, 116, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 80,
97, 114, 116, 105, 116, 105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 32, 83, 111, 114, 116,
101, 100, 79, 112, 116, 105, 111, 110, 115, 63, 10, 83, 111, 114, 116, 101, 100, 79, 112, 116,
80, 97, 114, 116, 105, 116, 105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32,
83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 80, 97, 114, 116, 105, 116,
105, 111, 110, 79, 112, 116, 105, 111, 110, 115, 63, 10, 80, 97, 114, 116, 105, 116, 105, 111,
110, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 39, 80, 65, 82, 84, 73, 84, 73,
79, 78, 69, 68, 39, 32, 39, 66, 89, 39, 32, 80, 97, 114, 101, 110, 115, 40, 76, 105,
115, 116, 40, 69, 120, 112, 114, 101, 115, 115, 105, 111, 110, 41, 41, 10, 83, 111, 114, 116,
101, 100, 79, 112, 116, 105, 111, 110, 115, 32, 60, 45, 32, 39, 83, 79, 82, 84, 69, 68,
39, 32, 39, 66, 89, 39, 32, 80, 97, 114, 101, 110, 115, 40, 76, 105, 115, 116, 40, 69,
120, 112, 114, 101, 115, 115, 105, 111, 110, 41, 41, 10, 87, 105, 116, 104, 68, 97, 116, 97,
32, 60, 45, 32, 87, 105, 116, 104, 68, 97, 116, 97, 79, 110, 108, 121, 32, 47, 32, 87,
105, 116, 104, 78, 111, 68, 97, 116, 97, 10, 87, 105, 116, 104, 68, 97, 116, 97, 79, 110,
108, 121, 32, 60, 45, 32, 39, 87, 73, 84, 72, 39, 32, 39, 68, 65, 84, 65, 39, 10,
87, 105, 116, 104, 78, 111, 68, 97, 116, 97, 32, 60, 45, 32, 39, 87, 73, 84, 72, 39,
32, 39, 78, 79, 39, 32, 39, 68, 65, 84, 65, 39, 10, 73, 100, 101, 110, 116, 105, 102,
105, 101, 114, 76, 105, 115, 116, 32, 60, 45, 32, 80, 97, 114, 101, 110, 115, 40, 76, 105,
115, 116, 40, 73, 100, 101, 110, 116, 105, 102, 105, 101, 114, 41, 41, 10, 67, 114, 101, 97,
116, 101, 67, 111, 108, 117, 109, 110, 76, 105, 115, 116, 32, 60, 45, 32, 67, 114, 101, 97,
116, 101, 84, 97, 98, 108, 101, 67, 111, 108, 117, 109, 110, 115, 63, 32, 80, 97, 114, 116,
105, 116, 105, 111, 110, 83, 111, 114, 116, 101, 100, 79, 112, 116, 105, 111, 110, 115, 63, 32,
87, 105, 116, 104, 76, 105, 115, 116, 63, 10, 67, 114, 101, 97, 116, 101, 84, 97, 98, 108,
101, 67, 111, 108, 117, 109, 110, 115, 32, 60, 45, 32, 80, 97, 114, 101, 110, 115, 40, 67,
114, 101, 97, 116, 101, 84, 97, 98, 108, 101, 67, 111, 108, 117, 109, 110, 76, 105, 115, 116,
63, 41, 10, 73, 102, 78, 111, 116, 69, 120, 105, 115, 116, 115, 32, 60, 45, 32, 39, 73,
70, 39, 32, 39, 78, 79, 84, 39, 32, 39, 69, 88, 73, 83, 84, 83, 39, 10, 81, 117,
97, 108, 105, 102, 105, 101, 100, 78, 97, 109, 101, 32, 60, 45, 32, 67, 97, 116, 97, 108,
111, 103, 82, 101, 115, 101, 114, 118, 101, 100, 83, 99, 104, 101, 109, 97, 73, 100, 101, 110,
Expand Down
25 changes: 19 additions & 6 deletions src/include/duckdb/parser/peg/transformer/peg_transformer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,12 @@ class PEGTransformerFactory {
static void InitializeCreateTableStmtTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeCreateTableStmtTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static void InitializeExternalTableTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeExternalTableTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static void InitializeTableTypeTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeTableTypeTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static void InitializeCreateTableDefinitionTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeCreateTableDefinitionTrampoline(PEGTransformer &transformer,
Expand Down Expand Up @@ -1605,6 +1611,9 @@ class PEGTransformerFactory {
static void InitializeCreateColumnListTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeCreateColumnListTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static void InitializeCreateTableColumnsTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeCreateTableColumnsTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
static void InitializeIfNotExistsTrampoline(PEGTransformer &transformer, GeneratedTransformProcess &process);
static unique_ptr<TransformResultValue> FinalizeIfNotExistsTrampoline(PEGTransformer &transformer,
GeneratedTransformProcess &process);
Expand Down Expand Up @@ -4494,11 +4503,13 @@ class PEGTransformerFactory {
static SecretPersistType TransformPersistent(PEGTransformer &transformer);
static SecretPersistType TransformTempPersistent(PEGTransformer &transformer);
static SecretPersistType TransformTemporaryPersistent(PEGTransformer &transformer);
static unique_ptr<CreateStatement> TransformCreateTableStmt(PEGTransformer &transformer,
const optional<bool> &if_not_exists,
const QualifiedName &qualified_name,
CreateTableDefinition create_table_definition,
const optional<bool> &commit_action);
static unique_ptr<CreateStatement>
TransformCreateTableStmt(PEGTransformer &transformer, const optional<bool> &external_table,
const optional<Identifier> &table_type, const optional<bool> &if_not_exists,
const QualifiedName &qualified_name, CreateTableDefinition create_table_definition,
const optional<bool> &commit_action);
static bool TransformExternalTable(PEGTransformer &transformer);
static Identifier TransformTableType(PEGTransformer &transformer, const Identifier &identifier);
static CreateTableDefinition
TransformCreateTableAs(PEGTransformer &transformer, optional<ColumnList> identifier_list,
optional<PartitionSortedOptions> partition_sorted_options,
Expand All @@ -4519,9 +4530,11 @@ class PEGTransformerFactory {
static bool TransformWithNoData(PEGTransformer &transformer);
static ColumnList TransformIdentifierList(PEGTransformer &transformer, const vector<Identifier> &identifier);
static CreateTableDefinition
TransformCreateColumnList(PEGTransformer &transformer, optional<ColumnElements> create_table_column_list,
TransformCreateColumnList(PEGTransformer &transformer, optional<ColumnElements> create_table_columns,
optional<PartitionSortedOptions> partition_sorted_options,
optional<case_insensitive_map_t<unique_ptr<ParsedExpression>>> with_list);
static ColumnElements TransformCreateTableColumns(PEGTransformer &transformer,
optional<ColumnElements> create_table_column_list);
static bool TransformIfNotExists(PEGTransformer &transformer);
static QualifiedName
TransformSchemaReservedIdentifierOrStringLiteral(PEGTransformer &transformer,
Expand Down
14 changes: 14 additions & 0 deletions src/include/duckdb/storage/serialization/create_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@
"id": 206,
"name": "options",
"type": "case_insensitive_map_t<ParsedExpression*>"
},
{
"id": 207,
"name": "table_type",
"type": "string",
"default": "string()",
"version": "v2.0.0"
},
{
"id": 208,
"name": "external",
"type": "bool",
"default": "false",
"version": "v2.0.0"
}
],
"methods": {
Expand Down
16 changes: 14 additions & 2 deletions src/parser/parsed_data/create_table_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
#include "duckdb/catalog/catalog.hpp"
#include "duckdb/common/sql_identifier.hpp"

namespace duckdb {

Expand Down Expand Up @@ -32,6 +33,8 @@ unique_ptr<CreateInfo> CreateTableInfo::Copy() const {
for (auto &option : options) {
result->options.emplace(option.first, option.second->Copy());
}
result->table_type = table_type;
result->external = external;
if (query) {
result->query = unique_ptr_cast<SQLStatement, SelectStatement>(query->Copy());
}
Expand Down Expand Up @@ -68,15 +71,24 @@ string CreateTableInfo::ExtraOptionsToString() const {
}

string CreateTableInfo::ToString() const {
string ret = GetCreatePrefix("TABLE");
string entry = "TABLE";
if (!table_type.empty()) {
entry = SQLIdentifier::ToString(table_type) + " " + entry;
}
if (external) {
entry = "EXTERNAL " + entry;
}
string ret = GetCreatePrefix(entry);
ret += QualifiedNameToString();

if (query != nullptr) {
ret += TableCatalogEntry::ColumnNamesToSQL(columns);
ret += ExtraOptionsToString();
ret += " AS " + query->ToString();
} else {
ret += TableCatalogEntry::ColumnsToSQL(columns, constraints);
if (!columns.empty()) {
ret += TableCatalogEntry::ColumnsToSQL(columns, constraints);
}
ret += ExtraOptionsToString();
ret += ";";
}
Expand Down
Loading
Loading