PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
test_ddl_deparse.c
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2  * test_ddl_deparse.c
3  * Support functions for the test_ddl_deparse module
4  *
5  * Copyright (c) 2014-2017, PostgreSQL Global Development Group
6  *
7  * IDENTIFICATION
8  * src/test/modules/test_ddl_deparse/test_ddl_deparse.c
9  *----------------------------------------------------------------------
10  */
11 #include "postgres.h"
12 
13 #include "catalog/pg_type.h"
14 #include "tcop/deparse_utility.h"
15 #include "tcop/utility.h"
16 #include "utils/builtins.h"
17 
19 
23 
24 /*
25  * Return the textual representation of the struct type used to represent a
26  * command in struct CollectedCommand format.
27  */
28 Datum
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 }
64 
65 /*
66  * Return the command tag corresponding to a parse node contained in a
67  * CollectedCommand struct.
68  */
69 Datum
71 {
73 
74  if (!cmd->parsetree)
76 
78 }
79 
80 /*
81  * Return a text array representation of the subcommands of an ALTER TABLE
82  * command.
83  */
84 Datum
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
Datum get_command_type(PG_FUNCTION_ARGS)
struct CollectedCommand::@102::@104 alterTable
#define castNode(_type_, nodeptr)
Definition: nodes.h:578
#define TEXTOID
Definition: pg_type.h:324
Datum get_command_tag(PG_FUNCTION_ARGS)
AlterTableType subtype
Definition: parsenodes.h:1778
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
CollectedCommandType type
#define ERROR
Definition: elog.h:43
PG_FUNCTION_INFO_V1(get_command_type)
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:5135
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2036
uintptr_t Datum
Definition: postgres.h:372
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:331
text * cstring_to_text(const char *s)
Definition: varlena.c:149
#define lfirst(lc)
Definition: pg_list.h:106
Datum get_altertable_subcmdtypes(PG_FUNCTION_ARGS)
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5071
PG_MODULE_MAGIC
#define CStringGetTextDatum(s)
Definition: builtins.h:91
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
#define elog
Definition: elog.h:219
#define PG_RETURN_NULL()
Definition: fmgr.h:305