I am working on creating a function in C-language in Apache AGE extension that performs an ALTER TABLE command to inherit from a parent table.
According to the PostgreSQL documentation for CREATE TABLE, the INHERITS keyword can take a list of parent tables. However, in the documentation for ALTER TABLE, it only mentions inheriting from a single parent table using the syntax INHERIT parent_table.
My question is whether it's possible to inherit from a list of parent tables using the ALTER TABLE command in PostgreSQL. If so, what would be the correct syntax to achieve this? PS: I'm using the version 11 of PostgreSQL.
Here's the function I'm creating (it's not working, system shutting down unexpectedly)
static void alter_table_inherit(char *graph_name, char *label_name,
char *schema_name, char *seq_name,
Oid relid, List* parents)
{
ParseState *pstate;
AlterTableStmt *tbl_stmt;
AlterTableCmd *tbl_cmd;
RangeVar *rv;
/* RangeVar represents the table being altered */
rv = makeRangeVar(schema_name, label_name, -1);
pstate = make_parsestate(NULL);
pstate->p_sourcetext = "(generated ALTER TABLE command)";
tbl_stmt = makeNode(AlterTableStmt);
tbl_stmt->relation = rv;
tbl_stmt->missing_ok = false;
tbl_cmd = makeNode(AlterTableCmd);
tbl_cmd->subtype = AT_AddInherit;
tbl_cmd->def = (Node *) parents;
tbl_stmt->cmds = lappend(tbl_stmt->cmds, tbl_cmd);
tbl_stmt->cmds = list_make1(tbl_cmd);
AlterTable(relid, AccessExclusiveLock, tbl_stmt);
CommandCounterIncrement();
}