Skip to content

Commit cea6ea5

Browse files
committed
wrote a drop_table() function
1 parent fcc7ead commit cea6ea5

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/pl_range_funcs.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "catalog/namespace.h"
2020
#include "catalog/pg_type.h"
2121
#include "catalog/heap.h"
22+
#include "commands/tablecmds.h"
2223
#include "executor/spi.h"
2324
#include "parser/parse_relation.h"
2425
#include "parser/parse_expr.h"
@@ -44,6 +45,7 @@ static void recreate_range_constraint(Oid partition,
4445
const Bound *lower,
4546
const Bound *upper);
4647
static char *get_qualified_rel_name(Oid relid);
48+
static void drop_table(Oid relid);
4749

4850
/* Function declarations */
4951

@@ -565,7 +567,9 @@ merge_range_partitions_internal(Oid parent, Oid *partitions, uint32 npart)
565567
if (SPI_connect() != SPI_OK_CONNECT)
566568
elog(ERROR, "could not connect using SPI");
567569

568-
/* Migrate the data from all partition to the first one */
570+
/*
571+
* Migrate the data from all partition to the first one
572+
*/
569573
for (i = 1; i < npart; i++)
570574
{
571575
char *query = psprintf("WITH part_data AS (DELETE FROM %s RETURNING *) "
@@ -576,20 +580,14 @@ merge_range_partitions_internal(Oid parent, Oid *partitions, uint32 npart)
576580
SPI_exec(query, 0);
577581
}
578582

583+
SPI_finish();
584+
579585
/*
580586
* Drop old partitions
581-
*
582-
* XXX Rewrite this in C
583587
*/
584588
for (i = 1; i < npart; i++)
585-
{
586-
char *query = psprintf("DROP TABLE %s",
587-
get_qualified_rel_name(partitions[i]));
588-
589-
SPI_exec(query, 0);
590-
}
589+
drop_table(partitions[i]);
591590

592-
SPI_finish();
593591
}
594592

595593
/*
@@ -676,3 +674,19 @@ get_qualified_rel_name(Oid relid)
676674
quote_identifier(get_namespace_name(namespace)),
677675
quote_identifier(get_rel_name(relid)));
678676
}
677+
678+
static void
679+
drop_table(Oid relid)
680+
{
681+
DropStmt *n = makeNode(DropStmt);
682+
const char *relname = get_qualified_rel_name(relid);
683+
684+
n->removeType = OBJECT_TABLE;
685+
n->missing_ok = false;
686+
n->objects = list_make1(stringToQualifiedNameList(relname));
687+
n->arguments = NIL;
688+
n->behavior = DROP_RESTRICT; // default behaviour
689+
n->concurrent = false;
690+
691+
RemoveRelations(n);
692+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy