mirror of
https://github.com/postgres/postgres.git
synced 2025-05-20 05:13:53 +03:00
Add some comments to test_ddl_deparse and a README
Per comments from Heikki Linnakangas. Backpatch to 9.5, where this module was introduced.
This commit is contained in:
parent
13f2db2ffb
commit
8f612b7f00
8
src/test/modules/test_ddl_deparse/README
Normal file
8
src/test/modules/test_ddl_deparse/README
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
test_ddl_deparse is an example of how to use the pg_ddl_command datatype.
|
||||||
|
It is not intended to do anything useful on its own; rather, it is a
|
||||||
|
demonstration of how to use the datatype, and to provide some unit tests for
|
||||||
|
it.
|
||||||
|
|
||||||
|
The functions in this extension are intended to be able to process some
|
||||||
|
part of the struct and produce some readable output, preferrably handling
|
||||||
|
all possible cases so that SQL test code can be written.
|
@ -1,3 +1,13 @@
|
|||||||
|
/*----------------------------------------------------------------------
|
||||||
|
* test_ddl_deparse.c
|
||||||
|
* Support functions for the test_ddl_deparse module
|
||||||
|
*
|
||||||
|
* Copyright (C) 2014-2015, PostgreSQL Global Development Group
|
||||||
|
*
|
||||||
|
* IDENTIFICATION
|
||||||
|
* src/test/modules/test_ddl_deparse/test_ddl_deparse.c
|
||||||
|
*----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
#include "catalog/pg_type.h"
|
#include "catalog/pg_type.h"
|
||||||
@ -11,6 +21,10 @@ PG_FUNCTION_INFO_V1(get_command_type);
|
|||||||
PG_FUNCTION_INFO_V1(get_command_tag);
|
PG_FUNCTION_INFO_V1(get_command_tag);
|
||||||
PG_FUNCTION_INFO_V1(get_altertable_subcmdtypes);
|
PG_FUNCTION_INFO_V1(get_altertable_subcmdtypes);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the textual representation of the struct type used to represent a
|
||||||
|
* command in struct CollectedCommand format.
|
||||||
|
*/
|
||||||
Datum
|
Datum
|
||||||
get_command_type(PG_FUNCTION_ARGS)
|
get_command_type(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
@ -48,6 +62,10 @@ get_command_type(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_TEXT_P(cstring_to_text(type));
|
PG_RETURN_TEXT_P(cstring_to_text(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the command tag corresponding to a parse node contained in a
|
||||||
|
* CollectedCommand struct.
|
||||||
|
*/
|
||||||
Datum
|
Datum
|
||||||
get_command_tag(PG_FUNCTION_ARGS)
|
get_command_tag(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
@ -59,6 +77,10 @@ get_command_tag(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_TEXT_P(cstring_to_text(CreateCommandTag(cmd->parsetree)));
|
PG_RETURN_TEXT_P(cstring_to_text(CreateCommandTag(cmd->parsetree)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a text array representation of the subcommands of an ALTER TABLE
|
||||||
|
* command.
|
||||||
|
*/
|
||||||
Datum
|
Datum
|
||||||
get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
|
get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
@ -130,6 +152,9 @@ get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
|
|||||||
case AT_ReAddConstraint:
|
case AT_ReAddConstraint:
|
||||||
strtype = "(re) ADD CONSTRAINT";
|
strtype = "(re) ADD CONSTRAINT";
|
||||||
break;
|
break;
|
||||||
|
case AT_ReAddComment:
|
||||||
|
strtype = "(re) ADD COMMENT";
|
||||||
|
break;
|
||||||
case AT_AlterConstraint:
|
case AT_AlterConstraint:
|
||||||
strtype = "ALTER CONSTRAINT";
|
strtype = "ALTER CONSTRAINT";
|
||||||
break;
|
break;
|
||||||
@ -258,6 +283,7 @@ get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strtype = "unrecognized";
|
strtype = "unrecognized";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
astate =
|
astate =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user