PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_ddl_deparse.c
Go to the documentation of this file.
1/*----------------------------------------------------------------------
2 * test_ddl_deparse.c
3 * Support functions for the test_ddl_deparse module
4 *
5 * Copyright (c) 2014-2026, PostgreSQL Global Development Group
6 *
7 * IDENTIFICATION
8 * src/test/modules/test_ddl_deparse/test_ddl_deparse.c
9 *----------------------------------------------------------------------
10 */
11#include "postgres.h"
12
13#include "funcapi.h"
14#include "nodes/execnodes.h"
16#include "tcop/utility.h"
17#include "utils/builtins.h"
18
20
24
25/*
26 * Return the textual representation of the struct type used to represent a
27 * command in struct CollectedCommand format.
28 */
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}
65
66/*
67 * Return the command tag corresponding to a parse node contained in a
68 * CollectedCommand struct.
69 */
80
81/*
82 * Return a text array representation of the subcommands of an ALTER TABLE
83 * command.
84 */
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;
300 strtype = "SPLIT PARTITION";
301 break;
303 strtype = "MERGE PARTITIONS";
304 break;
305 case AT_AddIdentity:
306 strtype = "ADD IDENTITY";
307 break;
308 case AT_SetIdentity:
309 strtype = "SET IDENTITY";
310 break;
311 case AT_DropIdentity:
312 strtype = "DROP IDENTITY";
313 break;
315 strtype = "(re) ADD STATS";
316 break;
317 }
318
319 if (subcmd->recurse)
320 values[0] = CStringGetTextDatum(psprintf("%s (and recurse)", strtype));
321 else
323 if (OidIsValid(sub->address.objectId))
324 {
325 char *objdesc;
326
327 objdesc = getObjectDescription((const ObjectAddress *) &sub->address, false);
329 }
330 else
331 nulls[1] = true;
332
333 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
334 }
335
336 return (Datum) 0;
337}
static Datum values[MAXATTR]
Definition bootstrap.c:155
#define CStringGetTextDatum(s)
Definition builtins.h:97
#define OidIsValid(objectId)
Definition c.h:788
@ SCT_Simple
@ SCT_AlterTSConfig
@ SCT_AlterDefaultPrivileges
@ SCT_Grant
@ SCT_CreateOpClass
@ SCT_AlterOpFamily
@ SCT_AlterTable
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_NULL()
Definition fmgr.h:346
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_RETURN_TEXT_P(x)
Definition fmgr.h:374
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
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::@132 d
CollectedCommandType type
struct CollectedCommand::@132::@134 alterTable
PG_MODULE_MAGIC
Datum get_altertable_subcmdinfo(PG_FUNCTION_ARGS)
Datum get_command_type(PG_FUNCTION_ARGS)
Datum get_command_tag(PG_FUNCTION_ARGS)
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:784
static const char * CreateCommandName(Node *parsetree)
Definition utility.h:103
text * cstring_to_text(const char *s)
Definition varlena.c:181
const char * type