PostgreSQL Source Code  git master
test_ddl_deparse.c File Reference
#include "postgres.h"
#include "funcapi.h"
#include "nodes/execnodes.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_subcmdinfo)
 
Datum get_command_type (PG_FUNCTION_ARGS)
 
Datum get_command_tag (PG_FUNCTION_ARGS)
 
Datum get_altertable_subcmdinfo (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

◆ get_altertable_subcmdinfo()

Datum get_altertable_subcmdinfo ( PG_FUNCTION_ARGS  )

Definition at line 86 of file test_ddl_deparse.c.

87 {
89  ListCell *cell;
90  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
91 
92  if (cmd->type != SCT_AlterTable)
93  elog(ERROR, "command is not ALTER TABLE");
94 
95  InitMaterializedSRF(fcinfo, 0);
96 
97  if (cmd->d.alterTable.subcmds == NIL)
98  elog(ERROR, "empty alter table subcommand list");
99 
100  foreach(cell, cmd->d.alterTable.subcmds)
101  {
102  CollectedATSubcmd *sub = lfirst(cell);
104  const char *strtype = "unrecognized";
105  Datum values[2];
106  bool nulls[2];
107 
108  memset(values, 0, sizeof(values));
109  memset(nulls, 0, sizeof(nulls));
110 
111  switch (subcmd->subtype)
112  {
113  case AT_AddColumn:
114  strtype = "ADD COLUMN";
115  break;
116  case AT_AddColumnToView:
117  strtype = "ADD COLUMN TO VIEW";
118  break;
119  case AT_ColumnDefault:
120  strtype = "ALTER COLUMN SET DEFAULT";
121  break;
123  strtype = "ALTER COLUMN SET DEFAULT (precooked)";
124  break;
125  case AT_DropNotNull:
126  strtype = "DROP NOT NULL";
127  break;
128  case AT_SetNotNull:
129  strtype = "SET NOT NULL";
130  break;
131  case AT_SetExpression:
132  strtype = "SET EXPRESSION";
133  break;
134  case AT_DropExpression:
135  strtype = "DROP EXPRESSION";
136  break;
137  case AT_SetStatistics:
138  strtype = "SET STATS";
139  break;
140  case AT_SetOptions:
141  strtype = "SET OPTIONS";
142  break;
143  case AT_ResetOptions:
144  strtype = "RESET OPTIONS";
145  break;
146  case AT_SetStorage:
147  strtype = "SET STORAGE";
148  break;
149  case AT_SetCompression:
150  strtype = "SET COMPRESSION";
151  break;
152  case AT_DropColumn:
153  strtype = "DROP COLUMN";
154  break;
155  case AT_AddIndex:
156  strtype = "ADD INDEX";
157  break;
158  case AT_ReAddIndex:
159  strtype = "(re) ADD INDEX";
160  break;
161  case AT_AddConstraint:
162  strtype = "ADD CONSTRAINT";
163  break;
164  case AT_ReAddConstraint:
165  strtype = "(re) ADD CONSTRAINT";
166  break;
168  strtype = "(re) ADD DOMAIN CONSTRAINT";
169  break;
170  case AT_AlterConstraint:
171  strtype = "ALTER CONSTRAINT";
172  break;
174  strtype = "VALIDATE CONSTRAINT";
175  break;
177  strtype = "ADD CONSTRAINT (using index)";
178  break;
179  case AT_DropConstraint:
180  strtype = "DROP CONSTRAINT";
181  break;
182  case AT_ReAddComment:
183  strtype = "(re) ADD COMMENT";
184  break;
185  case AT_AlterColumnType:
186  strtype = "ALTER COLUMN SET TYPE";
187  break;
189  strtype = "ALTER COLUMN SET OPTIONS";
190  break;
191  case AT_ChangeOwner:
192  strtype = "CHANGE OWNER";
193  break;
194  case AT_ClusterOn:
195  strtype = "CLUSTER";
196  break;
197  case AT_DropCluster:
198  strtype = "DROP CLUSTER";
199  break;
200  case AT_SetLogged:
201  strtype = "SET LOGGED";
202  break;
203  case AT_SetUnLogged:
204  strtype = "SET UNLOGGED";
205  break;
206  case AT_DropOids:
207  strtype = "DROP OIDS";
208  break;
209  case AT_SetAccessMethod:
210  strtype = "SET ACCESS METHOD";
211  break;
212  case AT_SetTableSpace:
213  strtype = "SET TABLESPACE";
214  break;
215  case AT_SetRelOptions:
216  strtype = "SET RELOPTIONS";
217  break;
218  case AT_ResetRelOptions:
219  strtype = "RESET RELOPTIONS";
220  break;
222  strtype = "REPLACE RELOPTIONS";
223  break;
224  case AT_EnableTrig:
225  strtype = "ENABLE TRIGGER";
226  break;
227  case AT_EnableAlwaysTrig:
228  strtype = "ENABLE TRIGGER (always)";
229  break;
231  strtype = "ENABLE TRIGGER (replica)";
232  break;
233  case AT_DisableTrig:
234  strtype = "DISABLE TRIGGER";
235  break;
236  case AT_EnableTrigAll:
237  strtype = "ENABLE TRIGGER (all)";
238  break;
239  case AT_DisableTrigAll:
240  strtype = "DISABLE TRIGGER (all)";
241  break;
242  case AT_EnableTrigUser:
243  strtype = "ENABLE TRIGGER (user)";
244  break;
245  case AT_DisableTrigUser:
246  strtype = "DISABLE TRIGGER (user)";
247  break;
248  case AT_EnableRule:
249  strtype = "ENABLE RULE";
250  break;
251  case AT_EnableAlwaysRule:
252  strtype = "ENABLE RULE (always)";
253  break;
255  strtype = "ENABLE RULE (replica)";
256  break;
257  case AT_DisableRule:
258  strtype = "DISABLE RULE";
259  break;
260  case AT_AddInherit:
261  strtype = "ADD INHERIT";
262  break;
263  case AT_DropInherit:
264  strtype = "DROP INHERIT";
265  break;
266  case AT_AddOf:
267  strtype = "OF";
268  break;
269  case AT_DropOf:
270  strtype = "NOT OF";
271  break;
272  case AT_ReplicaIdentity:
273  strtype = "REPLICA IDENTITY";
274  break;
276  strtype = "ENABLE ROW SECURITY";
277  break;
279  strtype = "DISABLE ROW SECURITY";
280  break;
281  case AT_ForceRowSecurity:
282  strtype = "FORCE ROW SECURITY";
283  break;
285  strtype = "NO FORCE ROW SECURITY";
286  break;
287  case AT_GenericOptions:
288  strtype = "SET OPTIONS";
289  break;
290  case AT_DetachPartition:
291  strtype = "DETACH PARTITION";
292  break;
293  case AT_AttachPartition:
294  strtype = "ATTACH PARTITION";
295  break;
297  strtype = "DETACH PARTITION ... FINALIZE";
298  break;
299  case AT_AddIdentity:
300  strtype = "ADD IDENTITY";
301  break;
302  case AT_SetIdentity:
303  strtype = "SET IDENTITY";
304  break;
305  case AT_DropIdentity:
306  strtype = "DROP IDENTITY";
307  break;
308  case AT_ReAddStatistics:
309  strtype = "(re) ADD STATS";
310  break;
311  }
312 
313  if (subcmd->recurse)
314  values[0] = CStringGetTextDatum(psprintf("%s (and recurse)", strtype));
315  else
316  values[0] = CStringGetTextDatum(strtype);
317  if (OidIsValid(sub->address.objectId))
318  {
319  char *objdesc;
320 
321  objdesc = getObjectDescription((const ObjectAddress *) &sub->address, false);
322  values[1] = CStringGetTextDatum(objdesc);
323  }
324  else
325  nulls[1] = true;
326 
327  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
328  }
329 
330  return (Datum) 0;
331 }
static Datum values[MAXATTR]
Definition: bootstrap.c:150
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define OidIsValid(objectId)
Definition: c.h:778
@ SCT_AlterTable
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
@ AT_AddIndexConstraint
Definition: parsenodes.h:2381
@ AT_DropOf
Definition: parsenodes.h:2412
@ AT_SetOptions
Definition: parsenodes.h:2369
@ AT_DropIdentity
Definition: parsenodes.h:2424
@ AT_DisableTrigUser
Definition: parsenodes.h:2404
@ AT_DropNotNull
Definition: parsenodes.h:2364
@ AT_AddOf
Definition: parsenodes.h:2411
@ AT_ResetOptions
Definition: parsenodes.h:2370
@ AT_ReplicaIdentity
Definition: parsenodes.h:2413
@ AT_ReplaceRelOptions
Definition: parsenodes.h:2396
@ AT_EnableRowSecurity
Definition: parsenodes.h:2414
@ AT_AddColumnToView
Definition: parsenodes.h:2361
@ AT_ResetRelOptions
Definition: parsenodes.h:2395
@ AT_EnableReplicaTrig
Definition: parsenodes.h:2399
@ AT_DropOids
Definition: parsenodes.h:2391
@ AT_SetIdentity
Definition: parsenodes.h:2423
@ AT_ReAddStatistics
Definition: parsenodes.h:2425
@ AT_SetUnLogged
Definition: parsenodes.h:2390
@ AT_DisableTrig
Definition: parsenodes.h:2400
@ AT_SetCompression
Definition: parsenodes.h:2372
@ AT_DropExpression
Definition: parsenodes.h:2367
@ AT_AddIndex
Definition: parsenodes.h:2374
@ AT_EnableReplicaRule
Definition: parsenodes.h:2407
@ AT_ReAddIndex
Definition: parsenodes.h:2375
@ AT_DropConstraint
Definition: parsenodes.h:2382
@ AT_SetNotNull
Definition: parsenodes.h:2365
@ AT_ClusterOn
Definition: parsenodes.h:2387
@ AT_AddIdentity
Definition: parsenodes.h:2422
@ AT_ForceRowSecurity
Definition: parsenodes.h:2416
@ AT_EnableAlwaysRule
Definition: parsenodes.h:2406
@ AT_SetAccessMethod
Definition: parsenodes.h:2392
@ AT_AlterColumnType
Definition: parsenodes.h:2384
@ AT_DetachPartitionFinalize
Definition: parsenodes.h:2421
@ AT_AddInherit
Definition: parsenodes.h:2409
@ AT_ReAddDomainConstraint
Definition: parsenodes.h:2378
@ AT_EnableTrig
Definition: parsenodes.h:2397
@ AT_DropColumn
Definition: parsenodes.h:2373
@ AT_ReAddComment
Definition: parsenodes.h:2383
@ AT_AlterColumnGenericOptions
Definition: parsenodes.h:2385
@ AT_DisableTrigAll
Definition: parsenodes.h:2402
@ AT_EnableRule
Definition: parsenodes.h:2405
@ AT_NoForceRowSecurity
Definition: parsenodes.h:2417
@ AT_DetachPartition
Definition: parsenodes.h:2420
@ AT_SetStatistics
Definition: parsenodes.h:2368
@ AT_AttachPartition
Definition: parsenodes.h:2419
@ AT_AddConstraint
Definition: parsenodes.h:2376
@ AT_DropInherit
Definition: parsenodes.h:2410
@ AT_EnableAlwaysTrig
Definition: parsenodes.h:2398
@ AT_SetLogged
Definition: parsenodes.h:2389
@ AT_SetStorage
Definition: parsenodes.h:2371
@ AT_DisableRule
Definition: parsenodes.h:2408
@ AT_DisableRowSecurity
Definition: parsenodes.h:2415
@ AT_SetRelOptions
Definition: parsenodes.h:2394
@ AT_ChangeOwner
Definition: parsenodes.h:2386
@ AT_EnableTrigUser
Definition: parsenodes.h:2403
@ AT_SetExpression
Definition: parsenodes.h:2366
@ AT_ReAddConstraint
Definition: parsenodes.h:2377
@ AT_SetTableSpace
Definition: parsenodes.h:2393
@ AT_GenericOptions
Definition: parsenodes.h:2418
@ AT_ColumnDefault
Definition: parsenodes.h:2362
@ AT_CookedColumnDefault
Definition: parsenodes.h:2363
@ AT_AlterConstraint
Definition: parsenodes.h:2379
@ AT_EnableTrigAll
Definition: parsenodes.h:2401
@ AT_DropCluster
Definition: parsenodes.h:2388
@ AT_ValidateConstraint
Definition: parsenodes.h:2380
@ AT_AddColumn
Definition: parsenodes.h:2360
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
uintptr_t Datum
Definition: postgres.h:64
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
AlterTableType subtype
Definition: parsenodes.h:2438
ObjectAddress address
CollectedCommandType type
union CollectedCommand::@123 d
struct CollectedCommand::@123::@125 alterTable
TupleDesc setDesc
Definition: execnodes.h:343
Tuplestorestate * setResult
Definition: execnodes.h:342
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition: tuplestore.c:784

References CollectedATSubcmd::address, CollectedCommand::alterTable, AT_AddColumn, AT_AddColumnToView, AT_AddConstraint, AT_AddIdentity, AT_AddIndex, AT_AddIndexConstraint, AT_AddInherit, AT_AddOf, AT_AlterColumnGenericOptions, AT_AlterColumnType, AT_AlterConstraint, AT_AttachPartition, AT_ChangeOwner, AT_ClusterOn, AT_ColumnDefault, AT_CookedColumnDefault, AT_DetachPartition, AT_DetachPartitionFinalize, AT_DisableRowSecurity, AT_DisableRule, AT_DisableTrig, AT_DisableTrigAll, AT_DisableTrigUser, AT_DropCluster, AT_DropColumn, AT_DropConstraint, AT_DropExpression, AT_DropIdentity, 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_ReAddComment, AT_ReAddConstraint, AT_ReAddDomainConstraint, AT_ReAddIndex, AT_ReAddStatistics, AT_ReplaceRelOptions, AT_ReplicaIdentity, AT_ResetOptions, AT_ResetRelOptions, AT_SetAccessMethod, AT_SetCompression, AT_SetExpression, AT_SetIdentity, AT_SetLogged, AT_SetNotNull, AT_SetOptions, AT_SetRelOptions, AT_SetStatistics, AT_SetStorage, AT_SetTableSpace, AT_SetUnLogged, AT_ValidateConstraint, castNode, CStringGetTextDatum, CollectedCommand::d, elog, ERROR, getObjectDescription(), if(), InitMaterializedSRF(), lfirst, NIL, ObjectAddress::objectId, OidIsValid, CollectedATSubcmd::parsetree, PG_GETARG_POINTER, psprintf(), AlterTableCmd::recurse, SCT_AlterTable, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, AlterTableCmd::subtype, tuplestore_putvalues(), CollectedCommand::type, and values.

◆ get_command_tag()

Datum get_command_tag ( PG_FUNCTION_ARGS  )

Definition at line 71 of file test_ddl_deparse.c.

72 {
74 
75  if (!cmd->parsetree)
77 
79 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345
#define PG_RETURN_TEXT_P(x)
Definition: fmgr.h:372
static const char * CreateCommandName(Node *parsetree)
Definition: utility.h:103
text * cstring_to_text(const char *s)
Definition: varlena.c:184

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

◆ get_command_type()

Datum get_command_type ( PG_FUNCTION_ARGS  )

Definition at line 30 of file test_ddl_deparse.c.

31 {
33  const char *type;
34 
35  switch (cmd->type)
36  {
37  case SCT_Simple:
38  type = "simple";
39  break;
40  case SCT_AlterTable:
41  type = "alter table";
42  break;
43  case SCT_Grant:
44  type = "grant";
45  break;
46  case SCT_AlterOpFamily:
47  type = "alter operator family";
48  break;
50  type = "alter default privileges";
51  break;
52  case SCT_CreateOpClass:
53  type = "create operator class";
54  break;
55  case SCT_AlterTSConfig:
56  type = "alter text search configuration";
57  break;
58  default:
59  type = "unknown command type";
60  break;
61  }
62 
64 }
@ SCT_Simple
@ SCT_AlterTSConfig
@ SCT_AlterDefaultPrivileges
@ SCT_Grant
@ SCT_CreateOpClass
@ SCT_AlterOpFamily
const char * type

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, type, and CollectedCommand::type.

◆ PG_FUNCTION_INFO_V1() [1/3]

PG_FUNCTION_INFO_V1 ( get_altertable_subcmdinfo  )

◆ PG_FUNCTION_INFO_V1() [2/3]

PG_FUNCTION_INFO_V1 ( get_command_tag  )

◆ PG_FUNCTION_INFO_V1() [3/3]

PG_FUNCTION_INFO_V1 ( get_command_type  )

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 19 of file test_ddl_deparse.c.