PostgreSQL Source Code  git master
test_ddl_deparse.c File Reference
#include "postgres.h"
#include "catalog/pg_type.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 87 of file test_ddl_deparse.c.

88 {
90  ListCell *cell;
91  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
92 
93  if (cmd->type != SCT_AlterTable)
94  elog(ERROR, "command is not ALTER TABLE");
95 
96  InitMaterializedSRF(fcinfo, 0);
97 
98  if (cmd->d.alterTable.subcmds == NIL)
99  elog(ERROR, "empty alter table subcommand list");
100 
101  foreach(cell, cmd->d.alterTable.subcmds)
102  {
103  CollectedATSubcmd *sub = lfirst(cell);
105  const char *strtype = "unrecognized";
106  Datum values[2];
107  bool nulls[2];
108 
109  memset(values, 0, sizeof(values));
110  memset(nulls, 0, sizeof(nulls));
111 
112  switch (subcmd->subtype)
113  {
114  case AT_AddColumn:
115  strtype = "ADD COLUMN";
116  break;
117  case AT_AddColumnRecurse:
118  strtype = "ADD COLUMN (and recurse)";
119  break;
120  case AT_AddColumnToView:
121  strtype = "ADD COLUMN TO VIEW";
122  break;
123  case AT_ColumnDefault:
124  strtype = "ALTER COLUMN SET DEFAULT";
125  break;
127  strtype = "ALTER COLUMN SET DEFAULT (precooked)";
128  break;
129  case AT_DropNotNull:
130  strtype = "DROP NOT NULL";
131  break;
132  case AT_SetNotNull:
133  strtype = "SET NOT NULL";
134  break;
135  case AT_DropExpression:
136  strtype = "DROP EXPRESSION";
137  break;
138  case AT_CheckNotNull:
139  strtype = "CHECK NOT NULL";
140  break;
141  case AT_SetStatistics:
142  strtype = "SET STATS";
143  break;
144  case AT_SetOptions:
145  strtype = "SET OPTIONS";
146  break;
147  case AT_ResetOptions:
148  strtype = "RESET OPTIONS";
149  break;
150  case AT_SetStorage:
151  strtype = "SET STORAGE";
152  break;
153  case AT_SetCompression:
154  strtype = "SET COMPRESSION";
155  break;
156  case AT_DropColumn:
157  strtype = "DROP COLUMN";
158  break;
160  strtype = "DROP COLUMN (and recurse)";
161  break;
162  case AT_AddIndex:
163  strtype = "ADD INDEX";
164  break;
165  case AT_ReAddIndex:
166  strtype = "(re) ADD INDEX";
167  break;
168  case AT_AddConstraint:
169  strtype = "ADD CONSTRAINT";
170  break;
172  strtype = "ADD CONSTRAINT (and recurse)";
173  break;
174  case AT_ReAddConstraint:
175  strtype = "(re) ADD CONSTRAINT";
176  break;
178  strtype = "(re) ADD DOMAIN CONSTRAINT";
179  break;
180  case AT_AlterConstraint:
181  strtype = "ALTER CONSTRAINT";
182  break;
184  strtype = "VALIDATE CONSTRAINT";
185  break;
187  strtype = "VALIDATE CONSTRAINT (and recurse)";
188  break;
190  strtype = "ADD CONSTRAINT (using index)";
191  break;
192  case AT_DropConstraint:
193  strtype = "DROP CONSTRAINT";
194  break;
196  strtype = "DROP CONSTRAINT (and recurse)";
197  break;
198  case AT_ReAddComment:
199  strtype = "(re) ADD COMMENT";
200  break;
201  case AT_AlterColumnType:
202  strtype = "ALTER COLUMN SET TYPE";
203  break;
205  strtype = "ALTER COLUMN SET OPTIONS";
206  break;
207  case AT_ChangeOwner:
208  strtype = "CHANGE OWNER";
209  break;
210  case AT_ClusterOn:
211  strtype = "CLUSTER";
212  break;
213  case AT_DropCluster:
214  strtype = "DROP CLUSTER";
215  break;
216  case AT_SetLogged:
217  strtype = "SET LOGGED";
218  break;
219  case AT_SetUnLogged:
220  strtype = "SET UNLOGGED";
221  break;
222  case AT_DropOids:
223  strtype = "DROP OIDS";
224  break;
225  case AT_SetAccessMethod:
226  strtype = "SET ACCESS METHOD";
227  break;
228  case AT_SetTableSpace:
229  strtype = "SET TABLESPACE";
230  break;
231  case AT_SetRelOptions:
232  strtype = "SET RELOPTIONS";
233  break;
234  case AT_ResetRelOptions:
235  strtype = "RESET RELOPTIONS";
236  break;
238  strtype = "REPLACE RELOPTIONS";
239  break;
240  case AT_EnableTrig:
241  strtype = "ENABLE TRIGGER";
242  break;
243  case AT_EnableAlwaysTrig:
244  strtype = "ENABLE TRIGGER (always)";
245  break;
247  strtype = "ENABLE TRIGGER (replica)";
248  break;
249  case AT_DisableTrig:
250  strtype = "DISABLE TRIGGER";
251  break;
252  case AT_EnableTrigAll:
253  strtype = "ENABLE TRIGGER (all)";
254  break;
255  case AT_DisableTrigAll:
256  strtype = "DISABLE TRIGGER (all)";
257  break;
258  case AT_EnableTrigUser:
259  strtype = "ENABLE TRIGGER (user)";
260  break;
261  case AT_DisableTrigUser:
262  strtype = "DISABLE TRIGGER (user)";
263  break;
264  case AT_EnableRule:
265  strtype = "ENABLE RULE";
266  break;
267  case AT_EnableAlwaysRule:
268  strtype = "ENABLE RULE (always)";
269  break;
271  strtype = "ENABLE RULE (replica)";
272  break;
273  case AT_DisableRule:
274  strtype = "DISABLE RULE";
275  break;
276  case AT_AddInherit:
277  strtype = "ADD INHERIT";
278  break;
279  case AT_DropInherit:
280  strtype = "DROP INHERIT";
281  break;
282  case AT_AddOf:
283  strtype = "OF";
284  break;
285  case AT_DropOf:
286  strtype = "NOT OF";
287  break;
288  case AT_ReplicaIdentity:
289  strtype = "REPLICA IDENTITY";
290  break;
292  strtype = "ENABLE ROW SECURITY";
293  break;
295  strtype = "DISABLE ROW SECURITY";
296  break;
297  case AT_ForceRowSecurity:
298  strtype = "FORCE ROW SECURITY";
299  break;
301  strtype = "NO FORCE ROW SECURITY";
302  break;
303  case AT_GenericOptions:
304  strtype = "SET OPTIONS";
305  break;
306  case AT_DetachPartition:
307  strtype = "DETACH PARTITION";
308  break;
309  case AT_AttachPartition:
310  strtype = "ATTACH PARTITION";
311  break;
313  strtype = "DETACH PARTITION ... FINALIZE";
314  break;
315  case AT_AddIdentity:
316  strtype = "ADD IDENTITY";
317  break;
318  case AT_SetIdentity:
319  strtype = "SET IDENTITY";
320  break;
321  case AT_DropIdentity:
322  strtype = "DROP IDENTITY";
323  break;
324  case AT_ReAddStatistics:
325  strtype = "(re) ADD STATS";
326  break;
327  }
328 
329  values[0] = CStringGetTextDatum(strtype);
330  if (OidIsValid(sub->address.objectId))
331  {
332  char *objdesc;
333  objdesc = getObjectDescription((const ObjectAddress *) &sub->address, false);
334  values[1] = CStringGetTextDatum(objdesc);
335  }
336  else
337  nulls[1] = true;
338 
339  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
340  }
341 
342  return (Datum) 0;
343 }
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:85
#define OidIsValid(objectId)
Definition: c.h:711
@ SCT_AlterTable
#define ERROR
Definition: elog.h:35
#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:77
#define castNode(_type_, nodeptr)
Definition: nodes.h:186
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
@ AT_AddIndexConstraint
Definition: parsenodes.h:1979
@ AT_DropOf
Definition: parsenodes.h:2011
@ AT_CheckNotNull
Definition: parsenodes.h:1962
@ AT_SetOptions
Definition: parsenodes.h:1964
@ AT_DropIdentity
Definition: parsenodes.h:2023
@ AT_DisableTrigUser
Definition: parsenodes.h:2003
@ AT_DropNotNull
Definition: parsenodes.h:1959
@ AT_AddOf
Definition: parsenodes.h:2010
@ AT_ResetOptions
Definition: parsenodes.h:1965
@ AT_ReplicaIdentity
Definition: parsenodes.h:2012
@ AT_DropColumnRecurse
Definition: parsenodes.h:1969
@ AT_ReplaceRelOptions
Definition: parsenodes.h:1995
@ AT_EnableRowSecurity
Definition: parsenodes.h:2013
@ AT_AddColumnToView
Definition: parsenodes.h:1956
@ AT_ResetRelOptions
Definition: parsenodes.h:1994
@ AT_AddConstraintRecurse
Definition: parsenodes.h:1973
@ AT_EnableReplicaTrig
Definition: parsenodes.h:1998
@ AT_DropOids
Definition: parsenodes.h:1990
@ AT_SetIdentity
Definition: parsenodes.h:2022
@ AT_ReAddStatistics
Definition: parsenodes.h:2024
@ AT_SetUnLogged
Definition: parsenodes.h:1989
@ AT_DisableTrig
Definition: parsenodes.h:1999
@ AT_SetCompression
Definition: parsenodes.h:1967
@ AT_DropExpression
Definition: parsenodes.h:1961
@ AT_AddIndex
Definition: parsenodes.h:1970
@ AT_EnableReplicaRule
Definition: parsenodes.h:2006
@ AT_ReAddIndex
Definition: parsenodes.h:1971
@ AT_DropConstraint
Definition: parsenodes.h:1980
@ AT_SetNotNull
Definition: parsenodes.h:1960
@ AT_ClusterOn
Definition: parsenodes.h:1986
@ AT_AddIdentity
Definition: parsenodes.h:2021
@ AT_ForceRowSecurity
Definition: parsenodes.h:2015
@ AT_EnableAlwaysRule
Definition: parsenodes.h:2005
@ AT_SetAccessMethod
Definition: parsenodes.h:1991
@ AT_AlterColumnType
Definition: parsenodes.h:1983
@ AT_DetachPartitionFinalize
Definition: parsenodes.h:2020
@ AT_AddInherit
Definition: parsenodes.h:2008
@ AT_ReAddDomainConstraint
Definition: parsenodes.h:1975
@ AT_EnableTrig
Definition: parsenodes.h:1996
@ AT_AddColumnRecurse
Definition: parsenodes.h:1955
@ AT_DropColumn
Definition: parsenodes.h:1968
@ AT_ValidateConstraintRecurse
Definition: parsenodes.h:1978
@ AT_ReAddComment
Definition: parsenodes.h:1982
@ AT_AlterColumnGenericOptions
Definition: parsenodes.h:1984
@ AT_DisableTrigAll
Definition: parsenodes.h:2001
@ AT_EnableRule
Definition: parsenodes.h:2004
@ AT_NoForceRowSecurity
Definition: parsenodes.h:2016
@ AT_DetachPartition
Definition: parsenodes.h:2019
@ AT_SetStatistics
Definition: parsenodes.h:1963
@ AT_AttachPartition
Definition: parsenodes.h:2018
@ AT_AddConstraint
Definition: parsenodes.h:1972
@ AT_DropInherit
Definition: parsenodes.h:2009
@ AT_EnableAlwaysTrig
Definition: parsenodes.h:1997
@ AT_SetLogged
Definition: parsenodes.h:1988
@ AT_SetStorage
Definition: parsenodes.h:1966
@ AT_DisableRule
Definition: parsenodes.h:2007
@ AT_DisableRowSecurity
Definition: parsenodes.h:2014
@ AT_SetRelOptions
Definition: parsenodes.h:1993
@ AT_ChangeOwner
Definition: parsenodes.h:1985
@ AT_EnableTrigUser
Definition: parsenodes.h:2002
@ AT_ReAddConstraint
Definition: parsenodes.h:1974
@ AT_DropConstraintRecurse
Definition: parsenodes.h:1981
@ AT_SetTableSpace
Definition: parsenodes.h:1992
@ AT_GenericOptions
Definition: parsenodes.h:2017
@ AT_ColumnDefault
Definition: parsenodes.h:1957
@ AT_CookedColumnDefault
Definition: parsenodes.h:1958
@ AT_AlterConstraint
Definition: parsenodes.h:1976
@ AT_EnableTrigAll
Definition: parsenodes.h:2000
@ AT_DropCluster
Definition: parsenodes.h:1987
@ AT_ValidateConstraint
Definition: parsenodes.h:1977
@ AT_AddColumn
Definition: parsenodes.h:1954
#define lfirst(lc)
Definition: pg_list.h:170
#define NIL
Definition: pg_list.h:66
uintptr_t Datum
Definition: postgres.h:412
AlterTableType subtype
Definition: parsenodes.h:2037
ObjectAddress address
CollectedCommandType type
union CollectedCommand::@109 d
struct CollectedCommand::@109::@111 alterTable
TupleDesc setDesc
Definition: execnodes.h:332
Tuplestorestate * setResult
Definition: execnodes.h:331
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750

References CollectedATSubcmd::address, CollectedCommand::alterTable, AT_AddColumn, AT_AddColumnRecurse, AT_AddColumnToView, AT_AddConstraint, AT_AddConstraintRecurse, AT_AddIdentity, AT_AddIndex, AT_AddIndexConstraint, AT_AddInherit, AT_AddOf, AT_AlterColumnGenericOptions, AT_AlterColumnType, AT_AlterConstraint, AT_AttachPartition, AT_ChangeOwner, AT_CheckNotNull, 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_DropColumnRecurse, AT_DropConstraint, AT_DropConstraintRecurse, 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_SetIdentity, AT_SetLogged, AT_SetNotNull, AT_SetOptions, AT_SetRelOptions, AT_SetStatistics, AT_SetStorage, AT_SetTableSpace, AT_SetUnLogged, AT_ValidateConstraint, AT_ValidateConstraintRecurse, castNode, CStringGetTextDatum, CollectedCommand::d, elog(), ERROR, getObjectDescription(), if(), InitMaterializedSRF(), lfirst, NIL, ObjectAddress::objectId, OidIsValid, CollectedATSubcmd::parsetree, PG_GETARG_POINTER, 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 72 of file test_ddl_deparse.c.

73 {
75 
76  if (!cmd->parsetree)
78 
80 }
#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:189

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 31 of file test_ddl_deparse.c.

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

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, generate_unaccent_rules::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 20 of file test_ddl_deparse.c.