1 /*-------------------------------------------------------------------------
2  *
3  * deparser.h
4  *	  Used when deparsing any ddl parsetree into its sql from.
5  *
6  * Copyright (c) Citus Data, Inc.
7  *
8  * $Id$
9  *
10  *-------------------------------------------------------------------------
11  */
12 
13 #ifndef CITUS_DEPARSER_H
14 #define CITUS_DEPARSER_H
15 
16 #include "postgres.h"
17 
18 #include "nodes/nodes.h"
19 #include "nodes/parsenodes.h"
20 #include "catalog/objectaddress.h"
21 #include "lib/stringinfo.h"
22 
23 /* forward declarations for format_collate.c */
24 /* Control flags for FormatCollateExtended, compatible with format_type_extended */
25 #define FORMAT_COLLATE_ALLOW_INVALID 0x02       /* allow invalid types */
26 #define FORMAT_COLLATE_FORCE_QUALIFY 0x04       /* force qualification of collate */
27 extern char * FormatCollateBEQualified(Oid collate_oid);
28 extern char * FormatCollateExtended(Oid collid, bits16 flags);
29 
30 extern void AssertObjectTypeIsFunctional(ObjectType type);
31 
32 extern void QualifyTreeNode(Node *stmt);
33 extern char * DeparseTreeNode(Node *stmt);
34 
35 /* forward declarations for deparse_attribute_stmts.c */
36 extern char * DeparseRenameAttributeStmt(Node *);
37 
38 /* forward declarations for deparse_collation_stmts.c */
39 extern char * DeparseDropCollationStmt(Node *stmt);
40 extern char * DeparseRenameCollationStmt(Node *stmt);
41 extern char * DeparseAlterCollationSchemaStmt(Node *stmt);
42 extern char * DeparseAlterCollationOwnerStmt(Node *stmt);
43 
44 extern void QualifyDropCollationStmt(Node *stmt);
45 extern void QualifyRenameCollationStmt(Node *stmt);
46 extern void QualifyAlterCollationSchemaStmt(Node *stmt);
47 extern void QualifyAlterCollationOwnerStmt(Node *stmt);
48 
49 /* forward declarations for deparse_table_stmts.c */
50 extern char * DeparseAlterTableSchemaStmt(Node *stmt);
51 extern char * DeparseAlterTableStmt(Node *node);
52 
53 extern void QualifyAlterTableSchemaStmt(Node *stmt);
54 
55 /* forward declarations for deparse_schema_stmts.c */
56 extern char * DeparseGrantOnSchemaStmt(Node *stmt);
57 extern char * DeparseAlterSchemaRenameStmt(Node *stmt);
58 
59 /* forward declarations for deparse_statistics_stmts.c */
60 extern char * DeparseCreateStatisticsStmt(Node *node);
61 extern char * DeparseDropStatisticsStmt(List *nameList, bool ifExists);
62 extern char * DeparseAlterStatisticsRenameStmt(Node *node);
63 extern char * DeparseAlterStatisticsSchemaStmt(Node *node);
64 extern char * DeparseAlterStatisticsStmt(Node *node);
65 extern char * DeparseAlterStatisticsOwnerStmt(Node *node);
66 
67 extern void QualifyCreateStatisticsStmt(Node *node);
68 extern void QualifyDropStatisticsStmt(Node *node);
69 extern void QualifyAlterStatisticsRenameStmt(Node *node);
70 extern void QualifyAlterStatisticsSchemaStmt(Node *node);
71 extern void QualifyAlterStatisticsStmt(Node *node);
72 extern void QualifyAlterStatisticsOwnerStmt(Node *node);
73 
74 /* forward declarations for deparse_type_stmts.c */
75 extern char * DeparseCompositeTypeStmt(Node *stmt);
76 extern char * DeparseCreateEnumStmt(Node *stmt);
77 extern char * DeparseDropTypeStmt(Node *stmt);
78 extern char * DeparseAlterEnumStmt(Node *stmt);
79 extern char * DeparseAlterTypeStmt(Node *stmt);
80 extern char * DeparseRenameTypeStmt(Node *stmt);
81 extern char * DeparseRenameTypeAttributeStmt(Node *stmt);
82 extern char * DeparseAlterTypeSchemaStmt(Node *stmt);
83 extern char * DeparseAlterTypeOwnerStmt(Node *stmt);
84 
85 extern void QualifyRenameAttributeStmt(Node *stmt);
86 extern void QualifyRenameTypeStmt(Node *stmt);
87 extern void QualifyRenameTypeAttributeStmt(Node *stmt);
88 extern void QualifyAlterEnumStmt(Node *stmt);
89 extern void QualifyAlterTypeStmt(Node *stmt);
90 extern void QualifyCompositeTypeStmt(Node *stmt);
91 extern void QualifyCreateEnumStmt(Node *stmt);
92 extern void QualifyAlterTypeSchemaStmt(Node *stmt);
93 extern void QualifyAlterTypeOwnerStmt(Node *stmt);
94 
95 extern ObjectAddress GetObjectAddressFromParseTree(Node *parseTree, bool missing_ok);
96 extern ObjectAddress RenameAttributeStmtObjectAddress(Node *stmt, bool missing_ok);
97 
98 /* forward declarations for deparse_function_stmts.c */
99 extern char * DeparseDropFunctionStmt(Node *stmt);
100 extern char * DeparseAlterFunctionStmt(Node *stmt);
101 
102 extern char * DeparseRenameFunctionStmt(Node *stmt);
103 extern char * DeparseAlterFunctionSchemaStmt(Node *stmt);
104 extern char * DeparseAlterFunctionOwnerStmt(Node *stmt);
105 extern char * DeparseAlterFunctionDependsStmt(Node *stmt);
106 
107 extern void AppendVariableSet(StringInfo buf, VariableSetStmt *setStmt);
108 
109 extern void QualifyAlterFunctionStmt(Node *stmt);
110 extern void QualifyRenameFunctionStmt(Node *stmt);
111 extern void QualifyAlterFunctionSchemaStmt(Node *stmt);
112 extern void QualifyAlterFunctionOwnerStmt(Node *stmt);
113 extern void QualifyAlterFunctionDependsStmt(Node *stmt);
114 
115 /* forward declarations for deparse_role_stmts.c */
116 extern char * DeparseAlterRoleStmt(Node *stmt);
117 extern char * DeparseAlterRoleSetStmt(Node *stmt);
118 
119 extern List * MakeSetStatementArguments(char *configurationName,
120 										char *configurationValue);
121 extern void QualifyAlterRoleSetStmt(Node *stmt);
122 
123 /* forward declarations for deparse_extension_stmts.c */
124 extern DefElem * GetExtensionOption(List *extensionOptions,
125 									const char *defname);
126 extern char * DeparseCreateExtensionStmt(Node *stmt);
127 extern char * DeparseDropExtensionStmt(Node *stmt);
128 extern char * DeparseAlterExtensionSchemaStmt(Node *stmt);
129 extern char * DeparseAlterExtensionStmt(Node *stmt);
130 
131 /* forward declarations for deparse_database_stmts.c */
132 extern char * DeparseAlterDatabaseOwnerStmt(Node *node);
133 
134 /* forward declarations for deparse_sequence_stmts.c */
135 extern char * DeparseDropSequenceStmt(Node *node);
136 extern char * DeparseRenameSequenceStmt(Node *node);
137 extern char * DeparseAlterSequenceSchemaStmt(Node *node);
138 extern char * DeparseAlterSequenceOwnerStmt(Node *node);
139 
140 /* forward declarations for qualify_sequence_stmt.c */
141 extern void QualifyRenameSequenceStmt(Node *node);
142 extern void QualifyAlterSequenceSchemaStmt(Node *node);
143 extern void QualifyAlterSequenceOwnerStmt(Node *node);
144 
145 #endif /* CITUS_DEPARSER_H */
146