Skip to content

Commit 8f612b7

Browse files
committed
Add some comments to test_ddl_deparse and a README
Per comments from Heikki Linnakangas. Backpatch to 9.5, where this module was introduced.
1 parent 13f2db2 commit 8f612b7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
test_ddl_deparse is an example of how to use the pg_ddl_command datatype.
2+
It is not intended to do anything useful on its own; rather, it is a
3+
demonstration of how to use the datatype, and to provide some unit tests for
4+
it.
5+
6+
The functions in this extension are intended to be able to process some
7+
part of the struct and produce some readable output, preferrably handling
8+
all possible cases so that SQL test code can be written.

src/test/modules/test_ddl_deparse/test_ddl_deparse.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*----------------------------------------------------------------------
2+
* test_ddl_deparse.c
3+
* Support functions for the test_ddl_deparse module
4+
*
5+
* Copyright (C) 2014-2015, PostgreSQL Global Development Group
6+
*
7+
* IDENTIFICATION
8+
* src/test/modules/test_ddl_deparse/test_ddl_deparse.c
9+
*----------------------------------------------------------------------
10+
*/
111
#include "postgres.h"
212

313
#include "catalog/pg_type.h"
@@ -11,6 +21,10 @@ PG_FUNCTION_INFO_V1(get_command_type);
1121
PG_FUNCTION_INFO_V1(get_command_tag);
1222
PG_FUNCTION_INFO_V1(get_altertable_subcmdtypes);
1323

24+
/*
25+
* Return the textual representation of the struct type used to represent a
26+
* command in struct CollectedCommand format.
27+
*/
1428
Datum
1529
get_command_type(PG_FUNCTION_ARGS)
1630
{
@@ -48,6 +62,10 @@ get_command_type(PG_FUNCTION_ARGS)
4862
PG_RETURN_TEXT_P(cstring_to_text(type));
4963
}
5064

65+
/*
66+
* Return the command tag corresponding to a parse node contained in a
67+
* CollectedCommand struct.
68+
*/
5169
Datum
5270
get_command_tag(PG_FUNCTION_ARGS)
5371
{
@@ -59,6 +77,10 @@ get_command_tag(PG_FUNCTION_ARGS)
5977
PG_RETURN_TEXT_P(cstring_to_text(CreateCommandTag(cmd->parsetree)));
6078
}
6179

80+
/*
81+
* Return a text array representation of the subcommands of an ALTER TABLE
82+
* command.
83+
*/
6284
Datum
6385
get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
6486
{
@@ -130,6 +152,9 @@ get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
130152
case AT_ReAddConstraint:
131153
strtype = "(re) ADD CONSTRAINT";
132154
break;
155+
case AT_ReAddComment:
156+
strtype = "(re) ADD COMMENT";
157+
break;
133158
case AT_AlterConstraint:
134159
strtype = "ALTER CONSTRAINT";
135160
break;
@@ -258,6 +283,7 @@ get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
258283
break;
259284
default:
260285
strtype = "unrecognized";
286+
break;
261287
}
262288

263289
astate =

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