PostgreSQL Source Code  git master
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

◆ get_altertable_subcmdtypes()

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_AlterColumnGenericOptions, AT_AlterColumnType, AT_AlterConstraint, AT_ChangeOwner, AT_CheckNotNull, 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(), CollectedATSubcmd::parsetree, PG_GETARG_POINTER, PG_RETURN_ARRAYTYPE_P, SCT_AlterTable, AlterTableCmd::subtype, 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_CheckNotNull:
121  strtype = "CHECK NOT NULL";
122  break;
123  case AT_SetStatistics:
124  strtype = "SET STATS";
125  break;
126  case AT_SetOptions:
127  strtype = "SET OPTIONS";
128  break;
129  case AT_ResetOptions:
130  strtype = "RESET OPTIONS";
131  break;
132  case AT_SetStorage:
133  strtype = "SET STORAGE";
134  break;
135  case AT_DropColumn:
136  strtype = "DROP COLUMN";
137  break;
139  strtype = "DROP COLUMN (and recurse)";
140  break;
141  case AT_AddIndex:
142  strtype = "ADD INDEX";
143  break;
144  case AT_ReAddIndex:
145  strtype = "(re) ADD INDEX";
146  break;
147  case AT_AddConstraint:
148  strtype = "ADD CONSTRAINT";
149  break;
151  strtype = "ADD CONSTRAINT (and recurse)";
152  break;
153  case AT_ReAddConstraint:
154  strtype = "(re) ADD CONSTRAINT";
155  break;
156  case AT_AlterConstraint:
157  strtype = "ALTER CONSTRAINT";
158  break;
160  strtype = "VALIDATE CONSTRAINT";
161  break;
163  strtype = "VALIDATE CONSTRAINT (and recurse)";
164  break;
166  strtype = "ADD (processed) CONSTRAINT";
167  break;
169  strtype = "ADD CONSTRAINT (using index)";
170  break;
171  case AT_DropConstraint:
172  strtype = "DROP CONSTRAINT";
173  break;
175  strtype = "DROP CONSTRAINT (and recurse)";
176  break;
177  case AT_ReAddComment:
178  strtype = "(re) ADD COMMENT";
179  break;
180  case AT_AlterColumnType:
181  strtype = "ALTER COLUMN SET TYPE";
182  break;
184  strtype = "ALTER COLUMN SET OPTIONS";
185  break;
186  case AT_ChangeOwner:
187  strtype = "CHANGE OWNER";
188  break;
189  case AT_ClusterOn:
190  strtype = "CLUSTER";
191  break;
192  case AT_DropCluster:
193  strtype = "DROP CLUSTER";
194  break;
195  case AT_SetLogged:
196  strtype = "SET LOGGED";
197  break;
198  case AT_SetUnLogged:
199  strtype = "SET UNLOGGED";
200  break;
201  case AT_DropOids:
202  strtype = "DROP OIDS";
203  break;
204  case AT_SetTableSpace:
205  strtype = "SET TABLESPACE";
206  break;
207  case AT_SetRelOptions:
208  strtype = "SET RELOPTIONS";
209  break;
210  case AT_ResetRelOptions:
211  strtype = "RESET RELOPTIONS";
212  break;
214  strtype = "REPLACE RELOPTIONS";
215  break;
216  case AT_EnableTrig:
217  strtype = "ENABLE TRIGGER";
218  break;
219  case AT_EnableAlwaysTrig:
220  strtype = "ENABLE TRIGGER (always)";
221  break;
223  strtype = "ENABLE TRIGGER (replica)";
224  break;
225  case AT_DisableTrig:
226  strtype = "DISABLE TRIGGER";
227  break;
228  case AT_EnableTrigAll:
229  strtype = "ENABLE TRIGGER (all)";
230  break;
231  case AT_DisableTrigAll:
232  strtype = "DISABLE TRIGGER (all)";
233  break;
234  case AT_EnableTrigUser:
235  strtype = "ENABLE TRIGGER (user)";
236  break;
237  case AT_DisableTrigUser:
238  strtype = "DISABLE TRIGGER (user)";
239  break;
240  case AT_EnableRule:
241  strtype = "ENABLE RULE";
242  break;
243  case AT_EnableAlwaysRule:
244  strtype = "ENABLE RULE (always)";
245  break;
247  strtype = "ENABLE RULE (replica)";
248  break;
249  case AT_DisableRule:
250  strtype = "DISABLE RULE";
251  break;
252  case AT_AddInherit:
253  strtype = "ADD INHERIT";
254  break;
255  case AT_DropInherit:
256  strtype = "DROP INHERIT";
257  break;
258  case AT_AddOf:
259  strtype = "OF";
260  break;
261  case AT_DropOf:
262  strtype = "NOT OF";
263  break;
264  case AT_ReplicaIdentity:
265  strtype = "REPLICA IDENTITY";
266  break;
268  strtype = "ENABLE ROW SECURITY";
269  break;
271  strtype = "DISABLE ROW SECURITY";
272  break;
273  case AT_ForceRowSecurity:
274  strtype = "FORCE ROW SECURITY";
275  break;
277  strtype = "NO FORCE ROW SECURITY";
278  break;
279  case AT_GenericOptions:
280  strtype = "SET OPTIONS";
281  break;
282  default:
283  strtype = "unrecognized";
284  break;
285  }
286 
287  astate =
288  accumArrayResult(astate, CStringGetTextDatum(strtype),
289  false, TEXTOID, CurrentMemoryContext);
290  }
291 
292  if (astate == NULL)
293  elog(ERROR, "empty alter table subcommand list");
294 
296 }
union CollectedCommand::@111 d
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
AlterTableType subtype
Definition: parsenodes.h:1840
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
CollectedCommandType type
#define ERROR
Definition: elog.h:43
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:253
Datum makeArrayResult(ArrayBuildState *astate, MemoryContext rcontext)
Definition: arrayfuncs.c:5117
#define lfirst(lc)
Definition: pg_list.h:190
struct CollectedCommand::@111::@113 alterTable
ArrayBuildState * accumArrayResult(ArrayBuildState *astate, Datum dvalue, bool disnull, Oid element_type, MemoryContext rcontext)
Definition: arrayfuncs.c:5053
#define elog(elevel,...)
Definition: elog.h:228
#define CStringGetTextDatum(s)
Definition: builtins.h:83

◆ get_command_tag()

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:271
const char * CreateCommandTag(Node *parsetree)
Definition: utility.c:2093
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ get_command_type()

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, CollectedCommand::type, and generate_unaccent_rules::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:271
CollectedCommandType type
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:361
text * cstring_to_text(const char *s)
Definition: varlena.c:171

◆ PG_FUNCTION_INFO_V1() [1/3]

PG_FUNCTION_INFO_V1 ( get_command_type  )

◆ PG_FUNCTION_INFO_V1() [2/3]

PG_FUNCTION_INFO_V1 ( get_command_tag  )

◆ PG_FUNCTION_INFO_V1() [3/3]

PG_FUNCTION_INFO_V1 ( get_altertable_subcmdtypes  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 18 of file test_ddl_deparse.c.