Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcea6ea5

Browse files
committed
wrote a drop_table() function
1 parentfcc7ead commitcea6ea5

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
constBound*lower,
4546
constBound*upper);
4647
staticchar*get_qualified_rel_name(Oidrelid);
48+
staticvoiddrop_table(Oidrelid);
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+
staticvoid
679+
drop_table(Oidrelid)
680+
{
681+
DropStmt*n=makeNode(DropStmt);
682+
constchar*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)

[8]ページ先頭

©2009-2025 Movatter.jp