PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 "utils/tuplestore.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;
118 strtype = "ADD COLUMN TO VIEW";
119 break;
120 case AT_ColumnDefault:
121 strtype = "ALTER COLUMN SET DEFAULT";
122 break;
124 strtype = "ALTER COLUMN SET DEFAULT (precooked)";
125 break;
126 case AT_DropNotNull:
127 strtype = "DROP NOT NULL";
128 break;
129 case AT_SetNotNull:
130 strtype = "SET NOT NULL";
131 break;
132 case AT_SetExpression:
133 strtype = "SET EXPRESSION";
134 break;
136 strtype = "DROP EXPRESSION";
137 break;
138 case AT_SetStatistics:
139 strtype = "SET STATS";
140 break;
141 case AT_SetOptions:
142 strtype = "SET OPTIONS";
143 break;
144 case AT_ResetOptions:
145 strtype = "RESET OPTIONS";
146 break;
147 case AT_SetStorage:
148 strtype = "SET STORAGE";
149 break;
151 strtype = "SET COMPRESSION";
152 break;
153 case AT_DropColumn:
154 strtype = "DROP COLUMN";
155 break;
156 case AT_AddIndex:
157 strtype = "ADD INDEX";
158 break;
159 case AT_ReAddIndex:
160 strtype = "(re) ADD INDEX";
161 break;
162 case AT_AddConstraint:
163 strtype = "ADD CONSTRAINT";
164 break;
166 strtype = "(re) ADD CONSTRAINT";
167 break;
169 strtype = "(re) ADD DOMAIN CONSTRAINT";
170 break;
172 strtype = "ALTER CONSTRAINT";
173 break;
175 strtype = "VALIDATE CONSTRAINT";
176 break;
178 strtype = "ADD CONSTRAINT (using index)";
179 break;
181 strtype = "DROP CONSTRAINT";
182 break;
183 case AT_ReAddComment:
184 strtype = "(re) ADD COMMENT";
185 break;
187 strtype = "ALTER COLUMN SET TYPE";
188 break;
190 strtype = "ALTER COLUMN SET OPTIONS";
191 break;
192 case AT_ChangeOwner:
193 strtype = "CHANGE OWNER";
194 break;
195 case AT_ClusterOn:
196 strtype = "CLUSTER";
197 break;
198 case AT_DropCluster:
199 strtype = "DROP CLUSTER";
200 break;
201 case AT_SetLogged:
202 strtype = "SET LOGGED";
203 break;
204 case AT_SetUnLogged:
205 strtype = "SET UNLOGGED";
206 break;
207 case AT_DropOids:
208 strtype = "DROP OIDS";
209 break;
211 strtype = "SET ACCESS METHOD";
212 break;
213 case AT_SetTableSpace:
214 strtype = "SET TABLESPACE";
215 break;
216 case AT_SetRelOptions:
217 strtype = "SET RELOPTIONS";
218 break;
220 strtype = "RESET RELOPTIONS";
221 break;
223 strtype = "REPLACE RELOPTIONS";
224 break;
225 case AT_EnableTrig:
226 strtype = "ENABLE TRIGGER";
227 break;
229 strtype = "ENABLE TRIGGER (always)";
230 break;
232 strtype = "ENABLE TRIGGER (replica)";
233 break;
234 case AT_DisableTrig:
235 strtype = "DISABLE TRIGGER";
236 break;
237 case AT_EnableTrigAll:
238 strtype = "ENABLE TRIGGER (all)";
239 break;
241 strtype = "DISABLE TRIGGER (all)";
242 break;
244 strtype = "ENABLE TRIGGER (user)";
245 break;
247 strtype = "DISABLE TRIGGER (user)";
248 break;
249 case AT_EnableRule:
250 strtype = "ENABLE RULE";
251 break;
253 strtype = "ENABLE RULE (always)";
254 break;
256 strtype = "ENABLE RULE (replica)";
257 break;
258 case AT_DisableRule:
259 strtype = "DISABLE RULE";
260 break;
261 case AT_AddInherit:
262 strtype = "ADD INHERIT";
263 break;
264 case AT_DropInherit:
265 strtype = "DROP INHERIT";
266 break;
267 case AT_AddOf:
268 strtype = "OF";
269 break;
270 case AT_DropOf:
271 strtype = "NOT OF";
272 break;
274 strtype = "REPLICA IDENTITY";
275 break;
277 strtype = "ENABLE ROW SECURITY";
278 break;
280 strtype = "DISABLE ROW SECURITY";
281 break;
283 strtype = "FORCE ROW SECURITY";
284 break;
286 strtype = "NO FORCE ROW SECURITY";
287 break;
289 strtype = "SET OPTIONS";
290 break;
292 strtype = "DETACH PARTITION";
293 break;
295 strtype = "ATTACH PARTITION";
296 break;
298 strtype = "DETACH PARTITION ... FINALIZE";
299 break;
301 strtype = "SPLIT PARTITION";
302 break;
304 strtype = "MERGE PARTITIONS";
305 break;
306 case AT_AddIdentity:
307 strtype = "ADD IDENTITY";
308 break;
309 case AT_SetIdentity:
310 strtype = "SET IDENTITY";
311 break;
312 case AT_DropIdentity:
313 strtype = "DROP IDENTITY";
314 break;
316 strtype = "(re) ADD STATS";
317 break;
318 }
319
320 if (subcmd->recurse)
321 values[0] = CStringGetTextDatum(psprintf("%s (and recurse)", strtype));
322 else
324 if (OidIsValid(sub->address.objectId))
325 {
326 char *objdesc;
327
328 objdesc = getObjectDescription((const ObjectAddress *) &sub->address, false);
330 }
331 else
332 nulls[1] = true;
333
334 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
335 }
336
337 return (Datum) 0;
338}
static Datum values[MAXATTR]
Definition bootstrap.c:188
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define OidIsValid(objectId)
Definition c.h:860
@ SCT_AlterTable
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition funcapi.c:76
#define castNode(_type_, nodeptr)
Definition nodes.h:182
char * getObjectDescription(const ObjectAddress *object, bool missing_ok)
@ AT_AddIndexConstraint
@ AT_MergePartitions
@ AT_DropOf
@ AT_SetOptions
@ AT_DropIdentity
@ AT_DisableTrigUser
@ AT_DropNotNull
@ AT_AddOf
@ AT_ResetOptions
@ AT_ReplicaIdentity
@ AT_ReplaceRelOptions
@ AT_EnableRowSecurity
@ AT_AddColumnToView
@ AT_ResetRelOptions
@ AT_EnableReplicaTrig
@ AT_DropOids
@ AT_SetIdentity
@ AT_ReAddStatistics
@ AT_SetUnLogged
@ AT_DisableTrig
@ AT_SetCompression
@ AT_DropExpression
@ AT_AddIndex
@ AT_EnableReplicaRule
@ AT_ReAddIndex
@ AT_DropConstraint
@ AT_SetNotNull
@ AT_ClusterOn
@ AT_AddIdentity
@ AT_ForceRowSecurity
@ AT_EnableAlwaysRule
@ AT_SetAccessMethod
@ AT_AlterColumnType
@ AT_DetachPartitionFinalize
@ AT_AddInherit
@ AT_ReAddDomainConstraint
@ AT_EnableTrig
@ AT_DropColumn
@ AT_ReAddComment
@ AT_AlterColumnGenericOptions
@ AT_DisableTrigAll
@ AT_EnableRule
@ AT_NoForceRowSecurity
@ AT_DetachPartition
@ AT_SetStatistics
@ AT_AttachPartition
@ AT_AddConstraint
@ AT_DropInherit
@ AT_EnableAlwaysTrig
@ AT_SetLogged
@ AT_SetStorage
@ AT_DisableRule
@ AT_DisableRowSecurity
@ AT_SetRelOptions
@ AT_ChangeOwner
@ AT_EnableTrigUser
@ AT_SetExpression
@ AT_ReAddConstraint
@ AT_SetTableSpace
@ AT_GenericOptions
@ AT_ColumnDefault
@ AT_CookedColumnDefault
@ AT_AlterConstraint
@ AT_EnableTrigAll
@ AT_SplitPartition
@ AT_DropCluster
@ AT_ValidateConstraint
@ AT_AddColumn
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
ObjectAddress address
union CollectedCommand::@135 d
CollectedCommandType type
struct CollectedCommand::@135::@137 alterTable
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:785

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_MergePartitions, 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_SplitPartition, AT_ValidateConstraint, castNode, CStringGetTextDatum, CollectedCommand::d, elog, ERROR, fb(), getObjectDescription(), InitMaterializedSRF(), lfirst, NIL, ObjectAddress::objectId, OidIsValid, CollectedATSubcmd::parsetree, PG_GETARG_POINTER, psprintf(), SCT_AlterTable, CollectedCommand::subcmds, 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:346
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
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 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;
48 type = "alter operator family";
49 break;
51 type = "alter default privileges";
52 break;
54 type = "create operator class";
55 break;
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
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 20 of file test_ddl_deparse.c.