PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
test_ddl_deparse.c File Reference
#include "postgres.h"
#include "catalog/pg_type.h"
#include "tcop/deparse_utility.h"
#include "tcop/utility.h"
#include "utils/builtins.h"
Include dependency graph for test_ddl_deparse.c:

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (get_command_type)
 
 PG_FUNCTION_INFO_V1 (get_command_tag)
 
 PG_FUNCTION_INFO_V1 (get_altertable_subcmdtypes)
 
Datum get_command_type (PG_FUNCTION_ARGS)
 
Datum get_command_tag (PG_FUNCTION_ARGS)
 
Datum get_altertable_subcmdtypes (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

Datum get_altertable_subcmdtypes ( PG_FUNCTION_ARGS  )

Definition at line 85 of file test_ddl_deparse.c.

References accumArrayResult(), CollectedCommand::alterTable, AT_AddColumn, AT_AddColumnRecurse, AT_AddColumnToView, AT_AddConstraint, AT_AddConstraintRecurse, AT_AddIndex, AT_AddIndexConstraint, AT_AddInherit, AT_AddOf, AT_AddOids, AT_AddOidsRecurse, AT_AlterColumnGenericOptions, AT_AlterColumnType, AT_AlterConstraint, AT_ChangeOwner, AT_ClusterOn, AT_ColumnDefault, AT_DisableRowSecurity, AT_DisableRule, AT_DisableTrig, AT_DisableTrigAll, AT_DisableTrigUser, AT_DropCluster, AT_DropColumn, AT_DropColumnRecurse, AT_DropConstraint, AT_DropConstraintRecurse, AT_DropInherit, AT_DropNotNull, AT_DropOf, AT_DropOids, AT_EnableAlwaysRule, AT_EnableAlwaysTrig, AT_EnableReplicaRule, AT_EnableReplicaTrig, AT_EnableRowSecurity, AT_EnableRule, AT_EnableTrig, AT_EnableTrigAll, AT_EnableTrigUser, AT_ForceRowSecurity, AT_GenericOptions, AT_NoForceRowSecurity, AT_ProcessedConstraint, AT_ReAddComment, AT_ReAddConstraint, AT_ReAddIndex, AT_ReplaceRelOptions, AT_ReplicaIdentity, AT_ResetOptions, AT_ResetRelOptions, AT_SetLogged, AT_SetNotNull, AT_SetOptions, AT_SetRelOptions, AT_SetStatistics, AT_SetStorage, AT_SetTableSpace, AT_SetUnLogged, AT_ValidateConstraint, AT_ValidateConstraintRecurse, castNode, CStringGetTextDatum, CurrentMemoryContext, CollectedCommand::d, elog, ERROR, lfirst, makeArrayResult(), NULL, CollectedATSubcmd::parsetree, PG_GETARG_POINTER, PG_RETURN_ARRAYTYPE_P, SCT_AlterTable, AlterTableCmd::subtype, TEXTOID, and CollectedCommand::type.

86 {
88  ArrayBuildState *astate = NULL;
89  ListCell *cell;
90 
91  if (cmd->type != SCT_AlterTable)
92  elog(ERROR, "command is not ALTER TABLE");
93 
94  foreach(cell, cmd->d.alterTable.subcmds)
95  {
96  CollectedATSubcmd *sub = lfirst(cell);
98  const char *strtype;
99 
100  switch (subcmd->subtype)
101  {
102  case AT_AddColumn:
103  strtype = "ADD COLUMN";
104  break;
105  case AT_AddColumnRecurse:
106  strtype = "ADD COLUMN (and recurse)";
107  break;
108  case AT_AddColumnToView:
109  strtype = "ADD COLUMN TO VIEW";
110  break;
111  case AT_ColumnDefault:
112  strtype = "ALTER COLUMN SET DEFAULT";
113  break;
114  case AT_DropNotNull:
115  strtype = "DROP NOT NULL";
116  break;
117  case AT_SetNotNull:
118  strtype = "SET NOT NULL";
119  break;
120  case AT_SetStatistics:
121  strtype = "SET STATS";
122  break;
123  case AT_SetOptions:
124  strtype = "SET OPTIONS";
125  break;
126  case AT_ResetOptions:
127  strtype = "RESET OPTIONS";
128  break;
129  case AT_SetStorage:
130  strtype = "SET STORAGE";
131  break;
132  case AT_DropColumn:
133  strtype = "DROP COLUMN";
134  break;
136  strtype = "DROP COLUMN (and recurse)";
137  break;
138  case AT_AddIndex:
139  strtype = "ADD INDEX";
140  break;
141  case AT_ReAddIndex:
142  strtype = "(re) ADD INDEX";
143  break;
144  case AT_AddConstraint:
145  strtype = "ADD CONSTRAINT";
146  break;
148  strtype = "ADD CONSTRAINT (and recurse)";
149  break;
150  case AT_ReAddConstraint:
151  strtype = "(re) ADD CONSTRAINT";
152  break;
153  case AT_AlterConstraint:
154  strtype = "ALTER CONSTRAINT";
155  break;
157  strtype = "VALIDATE CONSTRAINT";
158  break;
160  strtype = "VALIDATE CONSTRAINT (and recurse)";
161  break;
163  strtype = "ADD (processed) CONSTRAINT";
164  break;
166  strtype = "ADD CONSTRAINT (using index)";
167  break;
168  case AT_DropConstraint:
169  strtype = "DROP CONSTRAINT";
170  break;
172  strtype = "DROP CONSTRAINT (and recurse)";
173  break;
174  case AT_ReAddComment:
175  strtype = "(re) ADD COMMENT";
176  break;
177  case AT_AlterColumnType:
178  strtype = "ALTER COLUMN SET TYPE";
179  break;
181  strtype = "ALTER COLUMN SET OPTIONS";
182  break;
183  case AT_ChangeOwner:
184  strtype = "CHANGE OWNER";
185  break;
186  case AT_ClusterOn:
187  strtype = "CLUSTER";
188  break;
189  case AT_DropCluster:
190  strtype = "DROP CLUSTER";
191  break;
192  case AT_SetLogged:
193  strtype = "SET LOGGED";
194  break;
195  case AT_SetUnLogged:
196  strtype = "SET UNLOGGED";
197  break;
198  case AT_AddOids:
199  strtype = "ADD OIDS";
200  break;
201  case AT_AddOidsRecurse:
202  strtype = "ADD OIDS (and recurse)";
203  break;
204  case AT_DropOids:
205  strtype = "DROP OIDS";
206  break;
207  case AT_SetTableSpace:
208  strtype = "SET TABLESPACE";
209  break;
210  case AT_SetRelOptions:
211  strtype = "SET RELOPTIONS";
212  break;
213  case AT_ResetRelOptions:
214  strtype = "RESET RELOPTIONS";
215  break;
217  strtype = "REPLACE RELOPTIONS";
218  break;
219  case AT_EnableTrig:
220  strtype = "ENABLE TRIGGER";
221  break;
222  case AT_EnableAlwaysTrig:
223  strtype = "ENABLE TRIGGER (always)";
224  break;
226  strtype = "ENABLE TRIGGER (replica)";
227  break;
228  case AT_DisableTrig:
229  strtype = "DISABLE TRIGGER";
230  break;
231  case AT_EnableTrigAll:
232  strtype = "ENABLE TRIGGER (all)";
233  break;
234  case AT_DisableTrigAll:
235  strtype = "DISABLE TRIGGER (all)";
236  break;
237  case AT_EnableTrigUser:
238  strtype = "ENABLE TRIGGER (user)";
239  break;
240  case AT_DisableTrigUser:
241  strtype = "DISABLE TRIGGER (user)";
242  break;
243  case AT_EnableRule:
244  strtype = "ENABLE RULE";
245  break;
246  case AT_EnableAlwaysRule:
247  strtype = "ENABLE RULE (always)";
248  break;
250  strtype = "ENABLE RULE (replica)";
251  break;
252  case AT_DisableRule:
253  strtype = "DISABLE RULE";
254  break;
255  case AT_AddInherit:
256  strtype = "ADD INHERIT";
257  break;
258  case AT_DropInherit:
259  strtype = "DROP INHERIT";
260  break;
261  case AT_AddOf:
262  strtype = "OF";
263  break;
264  case AT_DropOf:
265  strtype = "NOT OF";
266  break;
267  case AT_ReplicaIdentity:
268  strtype = "REPLICA IDENTITY";
269  break;
271  strtype = "ENABLE ROW SECURITY";
272  break;
274  strtype = "DISABLE ROW SECURITY";
275  break;
276  case AT_ForceRowSecurity:
277  strtype = "FORCE ROW SECURITY";
278  break;
280  strtype = "NO FORCE ROW SECURITY";
281  break;
282  case AT_GenericOptions:
283  strtype = "SET OPTIONS";
284  break;
285  default:
286  strtype = "unrecognized";
287  break;
288  }
289 
290  astate =
291  accumArrayResult(astate, CStringGetTextDatum(strtype),
292  false, TEXTOID, CurrentMemoryContext);
293  }
294 
295  if (astate == NULL)
296  elog(ERROR, "empty alter table subcommand list");
297 
299 }
union CollectedCommand::@102 d
struct CollectedCommand::@102::@104 alterTable
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
#define TEXTOID
Definition: pg_type.h:324
AlterTableType subtype
Definition: parsenodes.h:1772
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
CollectedCommandType type
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:37
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:246
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5054
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:4990
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define elog
Definition: elog.h:219
Datum get_command_tag ( PG_FUNCTION_ARGS  )

Definition at line 70 of file test_ddl_deparse.c.

References CreateCommandTag(), cstring_to_text(), CollectedCommand::parsetree, PG_GETARG_POINTER, PG_RETURN_NULL, and PG_RETURN_TEXT_P.

71 {
73 
74  if (!cmd->parsetree)
76 
78 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2036
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
text * cstring_to_text(const char *s)
Definition: varlena.c:149
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum get_command_type ( PG_FUNCTION_ARGS  )

Definition at line 29 of file test_ddl_deparse.c.

References cstring_to_text(), PG_GETARG_POINTER, PG_RETURN_TEXT_P, SCT_AlterDefaultPrivileges, SCT_AlterOpFamily, SCT_AlterTable, SCT_AlterTSConfig, SCT_CreateOpClass, SCT_Grant, SCT_Simple, and CollectedCommand::type.

30 {
32  const char *type;
33 
34  switch (cmd->type)
35  {
36  case SCT_Simple:
37  type = "simple";
38  break;
39  case SCT_AlterTable:
40  type = "alter table";
41  break;
42  case SCT_Grant:
43  type = "grant";
44  break;
45  case SCT_AlterOpFamily:
46  type = "alter operator family";
47  break;
49  type = "alter default privileges";
50  break;
51  case SCT_CreateOpClass:
52  type = "create operator class";
53  break;
54  case SCT_AlterTSConfig:
55  type = "alter text search configuration";
56  break;
57  default:
58  type = "unknown command type";
59  break;
60  }
61 
63 }
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
CollectedCommandType type
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:330
text * cstring_to_text(const char *s)
Definition: varlena.c:149
PG_FUNCTION_INFO_V1 ( get_command_type  )
PG_FUNCTION_INFO_V1 ( get_command_tag  )
PG_FUNCTION_INFO_V1 ( get_altertable_subcmdtypes  )

Variable Documentation

PG_MODULE_MAGIC

Definition at line 18 of file test_ddl_deparse.c.