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;
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;
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;
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;
165 strtype = "(re) ADD CONSTRAINT";
166 break;
168 strtype = "(re) ADD DOMAIN CONSTRAINT";
169 break;
171 strtype = "ALTER CONSTRAINT";
172 break;
174 strtype = "VALIDATE CONSTRAINT";
175 break;
177 strtype = "ADD CONSTRAINT (using index)";
178 break;
180 strtype = "DROP CONSTRAINT";
181 break;
182 case AT_ReAddComment:
183 strtype = "(re) ADD COMMENT";
184 break;
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;
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;
219 strtype = "RESET RELOPTIONS";
220 break;
222 strtype = "REPLACE RELOPTIONS";
223 break;
224 case AT_EnableTrig:
225 strtype = "ENABLE TRIGGER";
226 break;
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;
240 strtype = "DISABLE TRIGGER (all)";
241 break;
243 strtype = "ENABLE TRIGGER (user)";
244 break;
246 strtype = "DISABLE TRIGGER (user)";
247 break;
248 case AT_EnableRule:
249 strtype = "ENABLE RULE";
250 break;
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;
273 strtype = "REPLICA IDENTITY";
274 break;
276 strtype = "ENABLE ROW SECURITY";
277 break;
279 strtype = "DISABLE ROW SECURITY";
280 break;
282 strtype = "FORCE ROW SECURITY";
283 break;
285 strtype = "NO FORCE ROW SECURITY";
286 break;
288 strtype = "SET OPTIONS";
289 break;
291 strtype = "DETACH PARTITION";
292 break;
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;
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:151
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define OidIsValid(objectId)
Definition: c.h:732
@ 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:2425
@ AT_DropOf
Definition: parsenodes.h:2456
@ AT_SetOptions
Definition: parsenodes.h:2413
@ AT_DropIdentity
Definition: parsenodes.h:2468
@ AT_DisableTrigUser
Definition: parsenodes.h:2448
@ AT_DropNotNull
Definition: parsenodes.h:2408
@ AT_AddOf
Definition: parsenodes.h:2455
@ AT_ResetOptions
Definition: parsenodes.h:2414
@ AT_ReplicaIdentity
Definition: parsenodes.h:2457
@ AT_ReplaceRelOptions
Definition: parsenodes.h:2440
@ AT_EnableRowSecurity
Definition: parsenodes.h:2458
@ AT_AddColumnToView
Definition: parsenodes.h:2405
@ AT_ResetRelOptions
Definition: parsenodes.h:2439
@ AT_EnableReplicaTrig
Definition: parsenodes.h:2443
@ AT_DropOids
Definition: parsenodes.h:2435
@ AT_SetIdentity
Definition: parsenodes.h:2467
@ AT_ReAddStatistics
Definition: parsenodes.h:2469
@ AT_SetUnLogged
Definition: parsenodes.h:2434
@ AT_DisableTrig
Definition: parsenodes.h:2444
@ AT_SetCompression
Definition: parsenodes.h:2416
@ AT_DropExpression
Definition: parsenodes.h:2411
@ AT_AddIndex
Definition: parsenodes.h:2418
@ AT_EnableReplicaRule
Definition: parsenodes.h:2451
@ AT_ReAddIndex
Definition: parsenodes.h:2419
@ AT_DropConstraint
Definition: parsenodes.h:2426
@ AT_SetNotNull
Definition: parsenodes.h:2409
@ AT_ClusterOn
Definition: parsenodes.h:2431
@ AT_AddIdentity
Definition: parsenodes.h:2466
@ AT_ForceRowSecurity
Definition: parsenodes.h:2460
@ AT_EnableAlwaysRule
Definition: parsenodes.h:2450
@ AT_SetAccessMethod
Definition: parsenodes.h:2436
@ AT_AlterColumnType
Definition: parsenodes.h:2428
@ AT_DetachPartitionFinalize
Definition: parsenodes.h:2465
@ AT_AddInherit
Definition: parsenodes.h:2453
@ AT_ReAddDomainConstraint
Definition: parsenodes.h:2422
@ AT_EnableTrig
Definition: parsenodes.h:2441
@ AT_DropColumn
Definition: parsenodes.h:2417
@ AT_ReAddComment
Definition: parsenodes.h:2427
@ AT_AlterColumnGenericOptions
Definition: parsenodes.h:2429
@ AT_DisableTrigAll
Definition: parsenodes.h:2446
@ AT_EnableRule
Definition: parsenodes.h:2449
@ AT_NoForceRowSecurity
Definition: parsenodes.h:2461
@ AT_DetachPartition
Definition: parsenodes.h:2464
@ AT_SetStatistics
Definition: parsenodes.h:2412
@ AT_AttachPartition
Definition: parsenodes.h:2463
@ AT_AddConstraint
Definition: parsenodes.h:2420
@ AT_DropInherit
Definition: parsenodes.h:2454
@ AT_EnableAlwaysTrig
Definition: parsenodes.h:2442
@ AT_SetLogged
Definition: parsenodes.h:2433
@ AT_SetStorage
Definition: parsenodes.h:2415
@ AT_DisableRule
Definition: parsenodes.h:2452
@ AT_DisableRowSecurity
Definition: parsenodes.h:2459
@ AT_SetRelOptions
Definition: parsenodes.h:2438
@ AT_ChangeOwner
Definition: parsenodes.h:2430
@ AT_EnableTrigUser
Definition: parsenodes.h:2447
@ AT_SetExpression
Definition: parsenodes.h:2410
@ AT_ReAddConstraint
Definition: parsenodes.h:2421
@ AT_SetTableSpace
Definition: parsenodes.h:2437
@ AT_GenericOptions
Definition: parsenodes.h:2462
@ AT_ColumnDefault
Definition: parsenodes.h:2406
@ AT_CookedColumnDefault
Definition: parsenodes.h:2407
@ AT_AlterConstraint
Definition: parsenodes.h:2423
@ AT_EnableTrigAll
Definition: parsenodes.h:2445
@ AT_DropCluster
Definition: parsenodes.h:2432
@ AT_ValidateConstraint
Definition: parsenodes.h:2424
@ AT_AddColumn
Definition: parsenodes.h:2404
#define lfirst(lc)
Definition: pg_list.h:172
#define NIL
Definition: pg_list.h:68
uintptr_t Datum
Definition: postgres.h:69
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
AlterTableType subtype
Definition: parsenodes.h:2482
ObjectAddress address
CollectedCommandType type
union CollectedCommand::@125 d
struct CollectedCommand::@125::@127 alterTable
TupleDesc setDesc
Definition: execnodes.h:358
Tuplestorestate * setResult
Definition: execnodes.h:357
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, CollectedCommand::subcmds, 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;
47 type = "alter operator family";
48 break;
50 type = "alter default privileges";
51 break;
53 type = "create operator class";
54 break;
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.