1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/parser/parsed_data/create_info.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/enums/catalog_type.hpp"
12#include "duckdb/common/field_writer.hpp"
13#include "duckdb/parser/parsed_data/parse_info.hpp"
14#include "duckdb/planner/plan_serialization.hpp"
15
16namespace duckdb {
17struct AlterInfo;
18
19enum class OnCreateConflict : uint8_t {
20 // Standard: throw error
21 ERROR_ON_CONFLICT,
22 // CREATE IF NOT EXISTS, silently do nothing on conflict
23 IGNORE_ON_CONFLICT,
24 // CREATE OR REPLACE
25 REPLACE_ON_CONFLICT,
26 // Update on conflict - only support for functions. Add a function overload if the function already exists.
27 ALTER_ON_CONFLICT
28};
29
30struct CreateInfo : public ParseInfo {
31 explicit CreateInfo(CatalogType type, string schema = DEFAULT_SCHEMA, string catalog_p = INVALID_CATALOG)
32 : type(type), catalog(std::move(catalog_p)), schema(schema), on_conflict(OnCreateConflict::ERROR_ON_CONFLICT),
33 temporary(false), internal(false) {
34 }
35 ~CreateInfo() override {
36 }
37
38 //! The to-be-created catalog type
39 CatalogType type;
40 //! The catalog name of the entry
41 string catalog;
42 //! The schema name of the entry
43 string schema;
44 //! What to do on create conflict
45 OnCreateConflict on_conflict;
46 //! Whether or not the entry is temporary
47 bool temporary;
48 //! Whether or not the entry is an internal entry
49 bool internal;
50 //! The SQL string of the CREATE statement
51 string sql;
52
53protected:
54 virtual void SerializeInternal(Serializer &) const = 0;
55
56 void DeserializeBase(Deserializer &deserializer);
57
58public:
59 void Serialize(Serializer &serializer) const;
60
61 static unique_ptr<CreateInfo> Deserialize(Deserializer &deserializer);
62 static unique_ptr<CreateInfo> Deserialize(Deserializer &deserializer, PlanDeserializationState &state);
63
64 virtual unique_ptr<CreateInfo> Copy() const = 0;
65
66 DUCKDB_API void CopyProperties(CreateInfo &other) const;
67 //! Generates an alter statement from the create statement - used for OnCreateConflict::ALTER_ON_CONFLICT
68 DUCKDB_API virtual unique_ptr<AlterInfo> GetAlterInfo() const;
69};
70
71} // namespace duckdb
72