Skip to content

Commit

Permalink
minimal sql macro example - works!
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Monahan committed Jul 2, 2024
1 parent c66ded0 commit 0c39826
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/dynamic_sql_examples_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
// OpenSSL linked through vcpkg
#include <openssl/opensslv.h>

#include "duckdb/catalog/default/default_functions.hpp"

namespace duckdb {

static DefaultMacro dynamic_sql_macros[] = {
{DEFAULT_SCHEMA, "times_two", {"x", nullptr}, "x*2"},
{nullptr, nullptr, {nullptr}, nullptr}};

inline void DynamicSqlExamplesScalarFun(DataChunk &args, ExpressionState &state, Vector &result) {
auto &name_vector = args.data[0];
UnaryExecutor::Execute<string_t, string_t>(
Expand Down Expand Up @@ -42,6 +48,13 @@ static void LoadInternal(DatabaseInstance &instance) {
auto dynamic_sql_examples_openssl_version_scalar_function = ScalarFunction("dynamic_sql_examples_openssl_version", {LogicalType::VARCHAR},
LogicalType::VARCHAR, DynamicSqlExamplesOpenSSLVersionScalarFun);
ExtensionUtil::RegisterFunction(instance, dynamic_sql_examples_openssl_version_scalar_function);

// macros
for (idx_t index = 0; dynamic_sql_macros[index].name != nullptr; index++) {
auto info = DefaultFunctionGenerator::CreateInternalMacroInfo(dynamic_sql_macros[index]);
ExtensionUtil::RegisterFunction(instance, *info);
}

}

void DynamicSqlExamplesExtension::Load(DuckDB &db) {
Expand Down

0 comments on commit 0c39826

Please sign in to comment.