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
28 changes: 28 additions & 0 deletions include/pgduckdb/pgduckdb_foreign_tables.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <string>

#include "pgduckdb/pg/declarations.hpp"

namespace pgduckdb {

// The name of the foreign server that we use for DuckDB foreign tables.
#define DUCKDB_FOREIGN_SERVER_NAME "duckdb"

void ValidateForeignIdentifier(const char *identifier, const char *context);

std::string BuildForeignTableFunctionCall(const char *reader, const char *location, void *options);

bool EnsureForeignTableLoaded(Oid relid);

void UnloadedForeignTable(Oid relid);

void ResetForeignTableCache();

bool IsForeignTableLoaded(Oid relid);

bool pgduckdb_is_foreign_relation(Oid relation_oid);

const char *ForeignTableServerName();

} // namespace pgduckdb
5 changes: 3 additions & 2 deletions include/pgduckdb/pgduckdb_ruleutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ char *pgduckdb_get_tabledef(Oid relation_id);
char *pgduckdb_get_alter_tabledef(Oid relation_oid, AlterTableStmt *alter_stmt);
char *pgduckdb_get_rename_relationdef(Oid relation_oid, RenameStmt *rename_stmt);
bool pgduckdb_is_not_default_expr(Node *node, void *context);
List *pgduckdb_db_and_schema(const char *postgres_schema_name, const char *duckdb_table_am_name);
const char *pgduckdb_db_and_schema_string(const char *postgres_schema_name, const char *duckdb_table_am_name);
List *pgduckdb_db_and_schema(const char *postgres_schema_name, const char *duckdb_table_am_name, bool is_ddb_foreign);
const char *pgduckdb_db_and_schema_string(const char *postgres_schema_name, const char *duckdb_table_am_name,
bool is_ddb_foreign);
bool pgduckdb_is_duckdb_row(Oid type_oid);
bool pgduckdb_is_unresolved_type(Oid type_oid);
bool pgduckdb_is_fake_type(Oid type_oid);
Expand Down
11 changes: 11 additions & 0 deletions sql/pg_duckdb--1.0.0--1.1.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,14 @@ CREATE FUNCTION duckdb.create_simple_secret(
RETURNS TEXT
SET search_path = pg_catalog, pg_temp
LANGUAGE C AS 'MODULE_PATHNAME', 'pgduckdb_create_simple_secret';

CREATE SERVER duckdb
TYPE 'foreign_table'
FOREIGN DATA WRAPPER duckdb;

GRANT USAGE ON FOREIGN SERVER duckdb TO public;

DROP EVENT TRIGGER IF EXISTS duckdb_alter_table_trigger;
CREATE EVENT TRIGGER duckdb_alter_foreign_table_trigger ON ddl_command_end
WHEN tag IN ('ALTER TABLE', 'ALTER FOREIGN TABLE')
EXECUTE FUNCTION duckdb._alter_table_trigger();
Loading