gitlab-pg_query 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,115 @@
1
+ require 'digest'
2
+
3
+ class PgQuery
4
+ def fingerprint
5
+ hash = Digest::SHA1.new
6
+ fingerprint_tree(hash)
7
+ format('%02x', FINGERPRINT_VERSION) + hash.hexdigest
8
+ end
9
+
10
+ private
11
+
12
+ FINGERPRINT_VERSION = 2
13
+
14
+ class FingerprintSubHash
15
+ attr_reader :parts
16
+
17
+ def initialize
18
+ @parts = []
19
+ end
20
+
21
+ def update(part)
22
+ @parts << part
23
+ end
24
+
25
+ def flush_to(hash)
26
+ parts.each do |part|
27
+ hash.update part
28
+ end
29
+ end
30
+ end
31
+
32
+ def ignored_fingerprint_value?(val)
33
+ [nil, 0, false, [], ''].include?(val)
34
+ end
35
+
36
+ def fingerprint_value(val, hash, parent_node_name, parent_field_name, need_to_write_name)
37
+ return if ignored_fingerprint_value?(val)
38
+
39
+ subhash = FingerprintSubHash.new
40
+
41
+ if val.is_a?(Hash)
42
+ fingerprint_node(val, subhash, parent_node_name, parent_field_name)
43
+ elsif val.is_a?(Array)
44
+ fingerprint_list(val, subhash, parent_node_name, parent_field_name)
45
+ else
46
+ subhash.update val.to_s
47
+ end
48
+
49
+ return if subhash.parts.empty?
50
+
51
+ hash.update(parent_field_name) if need_to_write_name
52
+ subhash.flush_to(hash)
53
+ end
54
+
55
+ def fingerprint_node(node, hash, parent_node_name = nil, parent_field_name = nil) # rubocop:disable Metrics/CyclomaticComplexity
56
+ node_name = node.keys.first
57
+ return if [A_CONST, ALIAS, PARAM_REF, SET_TO_DEFAULT, INT_LIST, OID_LIST, NULL].include?(node_name)
58
+
59
+ hash.update node_name
60
+
61
+ fields = node.values.first
62
+ fields.sort_by { |k, _| k }.each do |field_name, val|
63
+ next if ignored_fingerprint_value?(val)
64
+
65
+ case field_name
66
+ when 'location'
67
+ next
68
+ when 'name'
69
+ next if node_name == RES_TARGET && parent_node_name == SELECT_STMT && parent_field_name == TARGET_LIST_FIELD
70
+ next if [PREPARE_STMT, EXECUTE_STMT, DEALLOCATE_STMT].include?(node_name)
71
+ when 'gid'
72
+ next if node_name == TRANSACTION_STMT
73
+ when 'options'
74
+ next if node_name == TRANSACTION_STMT
75
+ when 'portalname'
76
+ next if [DECLARE_CURSOR_STMT, FETCH_STMT, CLOSE_PORTAL_STMT].include?(node_name)
77
+ when 'relname'
78
+ next if node_name == RANGE_VAR && fields[RELPERSISTENCE_FIELD] == 't'
79
+ when 'stmt_len'
80
+ next if node_name == RAW_STMT
81
+ when 'stmt_location'
82
+ next if node_name == RAW_STMT
83
+ end
84
+
85
+ fingerprint_value(val, hash, node_name, field_name, true)
86
+ end
87
+ end
88
+
89
+ def fingerprint_list(values, hash, parent_node_name, parent_field_name)
90
+ if [FROM_CLAUSE_FIELD, TARGET_LIST_FIELD, COLS_FIELD, REXPR_FIELD, VALUES_LISTS_FIELD].include?(parent_field_name)
91
+ values_subhashes = values.map do |val|
92
+ subhash = FingerprintSubHash.new
93
+ fingerprint_value(val, subhash, parent_node_name, parent_field_name, false)
94
+ subhash
95
+ end
96
+
97
+ values_subhashes.uniq!(&:parts)
98
+ values_subhashes.sort_by!(&:parts)
99
+
100
+ values_subhashes.each do |subhash|
101
+ subhash.flush_to(hash)
102
+ end
103
+ else
104
+ values.each do |val|
105
+ fingerprint_value(val, hash, parent_node_name, parent_field_name, false)
106
+ end
107
+ end
108
+ end
109
+
110
+ def fingerprint_tree(hash)
111
+ @tree.each do |node|
112
+ fingerprint_node(node, hash)
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,109 @@
1
+ class PgQuery
2
+ # Legacy parsetree from 0.7 and earlier versions - migrate to "tree" format if you can
3
+ def parsetree # rubocop:disable Metrics/CyclomaticComplexity
4
+ @parsetree ||= transform_nodes!(@tree) do |raw_node|
5
+ node = raw_node.keys[0] == RAW_STMT ? raw_node.delete(RAW_STMT)[STMT_FIELD] : raw_node
6
+
7
+ key = node.keys[0]
8
+ new_key = LEGACY_NODE_NAMES[key] || key.upcase
9
+
10
+ case key
11
+ when A_CONST
12
+ transform_parsetree_a_const(node)
13
+ when A_EXPR
14
+ node[A_EXPR]['name'] = transform_string_list(node[A_EXPR]['name'])
15
+ node[key].delete('kind')
16
+ when COLUMN_REF
17
+ node[COLUMN_REF]['fields'] = transform_string_list(node[COLUMN_REF]['fields'])
18
+ when CREATE_FUNCTION_STMT
19
+ node[CREATE_FUNCTION_STMT]['funcname'] = transform_string_list(node[CREATE_FUNCTION_STMT]['funcname'])
20
+ when CREATE_TRIG_STMT
21
+ node[CREATE_TRIG_STMT]['funcname'] = transform_string_list(node[CREATE_TRIG_STMT]['funcname'])
22
+ when CONSTRAINT
23
+ node[CONSTRAINT]['contype'] = LEGACY_CONSTRAINT_TYPES[node[CONSTRAINT]['contype']]
24
+ node[CONSTRAINT]['keys'] = transform_string_list(node[CONSTRAINT]['keys'])
25
+ when COPY_STMT
26
+ node[COPY_STMT]['attlist'] = transform_string_list(node[COPY_STMT]['attlist'])
27
+ when DEF_ELEM
28
+ node[DEF_ELEM]['arg'] = node[DEF_ELEM]['arg'][INTEGER]['ival'] if node[DEF_ELEM]['arg'].is_a?(Hash) && node[DEF_ELEM]['arg'].keys[0] == INTEGER
29
+ node[DEF_ELEM]['arg'] = node[DEF_ELEM]['arg'][STRING]['str'] if node[DEF_ELEM]['arg'].is_a?(Hash) && node[DEF_ELEM]['arg'].keys[0] == STRING
30
+ node[DEF_ELEM]['arg'] = transform_string_list(node[DEF_ELEM]['arg']) if node[DEF_ELEM]['arg'].is_a?(Array)
31
+ when DROP_STMT
32
+ node[DROP_STMT]['objects'].each_with_index do |obj, idx|
33
+ node[DROP_STMT]['objects'][idx] = transform_string_list(obj)
34
+ end
35
+ when FUNC_CALL
36
+ node[FUNC_CALL]['funcname'] = transform_string_list(node[FUNC_CALL]['funcname'])
37
+ when GRANT_ROLE_STMT
38
+ node[GRANT_ROLE_STMT]['grantee_roles'] = transform_string_list(node[GRANT_ROLE_STMT]['grantee_roles'])
39
+ when RANGE_VAR
40
+ node[RANGE_VAR]['inhOpt'] = node[RANGE_VAR].delete('inh') ? 2 : 0
41
+ when TYPE_NAME
42
+ node[TYPE_NAME]['names'] = transform_string_list(node[TYPE_NAME]['names'])
43
+ end
44
+
45
+ raw_node[new_key] = node.delete(key)
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ LEGACY_NODE_NAMES = {
52
+ A_EXPR => 'AEXPR',
53
+ SELECT_STMT => 'SELECT',
54
+ ALTER_TABLE_CMD => 'ALTER TABLE CMD',
55
+ ALTER_TABLE_STMT => 'ALTER TABLE',
56
+ CHECK_POINT_STMT => 'CHECKPOINT',
57
+ CREATE_SCHEMA_STMT => 'CREATE SCHEMA',
58
+ CREATE_TABLE_AS_STMT => 'CREATE TABLE AS',
59
+ COPY_STMT => 'COPY',
60
+ DELETE_STMT => 'DELETE FROM',
61
+ DROP_STMT => 'DROP',
62
+ INSERT_STMT => 'INSERT INTO',
63
+ EXPLAIN_STMT => 'EXPLAIN',
64
+ LOCK_STMT => 'LOCK',
65
+ TRANSACTION_STMT => 'TRANSACTION',
66
+ TRUNCATE_STMT => 'TRUNCATE',
67
+ UPDATE_STMT => 'UPDATE',
68
+ VACUUM_STMT => 'VACUUM',
69
+ VARIABLE_SET_STMT => 'SET',
70
+ VARIABLE_SHOW_STMT => 'SHOW'
71
+ # All others default to simply upper-casing the input name
72
+ }.freeze
73
+
74
+ LEGACY_CONSTRAINT_TYPES = {
75
+ CONSTR_TYPE_PRIMARY => 'PRIMARY_KEY'
76
+ }.freeze
77
+
78
+ def transform_parsetree_a_const(node)
79
+ type_key = node[A_CONST]['val'].keys[0]
80
+
81
+ case type_key
82
+ when INTEGER
83
+ node[A_CONST]['type'] = 'integer'
84
+ node[A_CONST]['val'] = node[A_CONST]['val'][INTEGER]['ival']
85
+ when STRING
86
+ node[A_CONST]['type'] = 'string'
87
+ node[A_CONST]['val'] = node[A_CONST]['val'][STRING]['str']
88
+ when FLOAT
89
+ node[A_CONST]['type'] = 'float'
90
+ node[A_CONST]['val'] = node[A_CONST]['val'][FLOAT]['str'].to_f
91
+ when BIT_STRING
92
+ node[A_CONST]['type'] = 'bitstring'
93
+ node[A_CONST]['val'] = node[A_CONST]['val'][BIT_STRING]['str']
94
+ when NULL
95
+ node[A_CONST]['type'] = 'null'
96
+ node[A_CONST]['val'] = nil
97
+ end
98
+ end
99
+
100
+ def transform_string_list(list)
101
+ return if list.nil?
102
+
103
+ if list.is_a?(Array)
104
+ list.map { |node| node.keys[0] == STRING ? node[STRING]['str'] : node }
105
+ else
106
+ [list.keys[0] == STRING ? list[STRING]['str'] : list]
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,296 @@
1
+ # rubocop:disable Style/ConstantName
2
+ class PgQuery
3
+ # NODE TYPES
4
+
5
+ A_ARRAY_EXPR = 'A_ArrayExpr'.freeze
6
+ A_CONST = 'A_Const'.freeze
7
+ A_EXPR = 'A_Expr'.freeze
8
+ A_INDICES = 'A_Indices'.freeze
9
+ A_INDIRECTION = 'A_Indirection'.freeze
10
+ A_STAR = 'A_Star'.freeze
11
+ ACCESS_PRIV = 'AccessPriv'.freeze
12
+ ALIAS = 'Alias'.freeze
13
+ ALTER_TABLE_CMD = 'AlterTableCmd'.freeze
14
+ ALTER_TABLE_STMT = 'AlterTableStmt'.freeze
15
+ BIT_STRING = 'BitString'.freeze
16
+ BOOL_EXPR = 'BoolExpr'.freeze
17
+ BOOLEAN_TEST = 'BooleanTest'.freeze
18
+ CASE_EXPR = 'CaseExpr'.freeze
19
+ CASE_WHEN = 'CaseWhen'.freeze
20
+ CHECK_POINT_STMT = 'CheckPointStmt'.freeze
21
+ CLOSE_PORTAL_STMT = 'ClosePortalStmt'.freeze
22
+ COALESCE_EXPR = 'CoalesceExpr'.freeze
23
+ COLLATE_CLAUSE = 'CollateClause'.freeze
24
+ COLUMN_DEF = 'ColumnDef'.freeze
25
+ COLUMN_REF = 'ColumnRef'.freeze
26
+ COMMON_TABLE_EXPR = 'CommonTableExpr'.freeze
27
+ COMPOSITE_TYPE_STMT = 'CompositeTypeStmt'.freeze
28
+ CONSTRAINT = 'Constraint'.freeze
29
+ COPY_STMT = 'CopyStmt'.freeze
30
+ CREATE_CAST_STMT = 'CreateCastStmt'.freeze
31
+ CREATE_DOMAIN_STMT = 'CreateDomainStmt'.freeze
32
+ CREATE_ENUM_STMT = 'CreateEnumStmt'.freeze
33
+ CREATE_FUNCTION_STMT = 'CreateFunctionStmt'.freeze
34
+ CREATE_RANGE_STMT = 'CreateRangeStmt'.freeze
35
+ CREATE_SCHEMA_STMT = 'CreateSchemaStmt'.freeze
36
+ CREATE_STMT = 'CreateStmt'.freeze
37
+ CREATE_TABLE_AS_STMT = 'CreateTableAsStmt'.freeze
38
+ CREATE_TRIG_STMT = 'CreateTrigStmt'.freeze
39
+ DEALLOCATE_STMT = 'DeallocateStmt'.freeze
40
+ DECLARE_CURSOR_STMT = 'DeclareCursorStmt'.freeze
41
+ DEF_ELEM = 'DefElem'.freeze
42
+ DEFINE_STMT = 'DefineStmt'.freeze
43
+ DELETE_STMT = 'DeleteStmt'.freeze
44
+ DISCARD_STMT = 'DiscardStmt'.freeze
45
+ DO_STMT = 'DoStmt'.freeze
46
+ DROP_STMT = 'DropStmt'.freeze
47
+ DROP_SUBSCRIPTION = 'DropSubscriptionStmt'.freeze
48
+ DROP_TABLESPACE = 'DropTableSpaceStmt'.freeze
49
+ DROP_ROLE = 'DropRoleStmt'.freeze
50
+ EXECUTE_STMT = 'ExecuteStmt'.freeze
51
+ EXPLAIN_STMT = 'ExplainStmt'.freeze
52
+ FETCH_STMT = 'FetchStmt'.freeze
53
+ FLOAT = 'Float'.freeze
54
+ FUNC_CALL = 'FuncCall'.freeze
55
+ FUNCTION_PARAMETER = 'FunctionParameter'.freeze
56
+ GRANT_ROLE_STMT = 'GrantRoleStmt'.freeze
57
+ GRANT_STMT = 'GrantStmt'.freeze
58
+ INDEX_ELEM = 'IndexElem'.freeze
59
+ INDEX_STMT = 'IndexStmt'.freeze
60
+ INSERT_STMT = 'InsertStmt'.freeze
61
+ INT_LIST = 'IntList'.freeze
62
+ INTEGER = 'Integer'.freeze
63
+ INTO_CLAUSE = 'IntoClause'.freeze
64
+ JOIN_EXPR = 'JoinExpr'.freeze
65
+ LOCK_STMT = 'LockStmt'.freeze
66
+ LOCKING_CLAUSE = 'LockingClause'.freeze
67
+ NULL = 'Null'.freeze
68
+ NULL_TEST = 'NullTest'.freeze
69
+ OBJECT_WITH_ARGS = 'ObjectWithArgs'.freeze
70
+ OID_LIST = 'OidList'.freeze
71
+ PARAM_REF = 'ParamRef'.freeze
72
+ PREPARE_STMT = 'PrepareStmt'.freeze
73
+ RANGE_FUNCTION = 'RangeFunction'.freeze
74
+ RANGE_SUBSELECT = 'RangeSubselect'.freeze
75
+ RANGE_VAR = 'RangeVar'.freeze
76
+ RAW_STMT = 'RawStmt'.freeze
77
+ REFRESH_MAT_VIEW_STMT = 'RefreshMatViewStmt'.freeze
78
+ RENAME_STMT = 'RenameStmt'.freeze
79
+ RES_TARGET = 'ResTarget'.freeze
80
+ ROLE_SPEC = 'RoleSpec'.freeze
81
+ ROW_EXPR = 'RowExpr'.freeze
82
+ RULE_STMT = 'RuleStmt'.freeze
83
+ SELECT_STMT = 'SelectStmt'.freeze
84
+ SET_TO_DEFAULT = 'SetToDefault'.freeze
85
+ SORT_BY = 'SortBy'.freeze
86
+ SQL_VALUE_FUNCTION = 'SQLValueFunction'.freeze
87
+ STRING = 'String'.freeze
88
+ SUB_LINK = 'SubLink'.freeze
89
+ TRANSACTION_STMT = 'TransactionStmt'.freeze
90
+ TRUNCATE_STMT = 'TruncateStmt'.freeze
91
+ TYPE_CAST = 'TypeCast'.freeze
92
+ TYPE_NAME = 'TypeName'.freeze
93
+ UPDATE_STMT = 'UpdateStmt'.freeze
94
+ VACUUM_STMT = 'VacuumStmt'.freeze
95
+ VARIABLE_SET_STMT = 'VariableSetStmt'.freeze
96
+ VARIABLE_SHOW_STMT = 'VariableShowStmt'.freeze
97
+ VIEW_STMT = 'ViewStmt'.freeze
98
+ WINDOW_DEF = 'WindowDef'.freeze
99
+ WITH_CLAUSE = 'WithClause'.freeze
100
+
101
+ # FIELDS
102
+
103
+ COLS_FIELD = 'cols'.freeze
104
+ FROM_CLAUSE_FIELD = 'fromClause'.freeze
105
+ RELPERSISTENCE_FIELD = 'relpersistence'.freeze
106
+ REXPR_FIELD = 'rexpr'.freeze
107
+ STMT_FIELD = 'stmt'.freeze
108
+ TARGET_LIST_FIELD = 'targetList'.freeze
109
+ VALUES_LISTS_FIELD = 'valuesLists'.freeze
110
+
111
+ # ENUMS
112
+
113
+ CONSTR_TYPE_NULL = 0 # not standard SQL, but a lot of people expect it
114
+ CONSTR_TYPE_NOTNULL = 1
115
+ CONSTR_TYPE_DEFAULT = 2
116
+ CONSTR_TYPE_IDENTITY = 3
117
+ CONSTR_TYPE_CHECK = 4
118
+ CONSTR_TYPE_PRIMARY = 5
119
+ CONSTR_TYPE_UNIQUE = 6
120
+ CONSTR_TYPE_EXCLUSION = 7
121
+ CONSTR_TYPE_FOREIGN = 8
122
+ CONSTR_TYPE_ATTR_DEFERRABLE = 9 # attributes for previous constraint node
123
+ CONSTR_TYPE_ATTR_NOT_DEFERRABLE = 10
124
+ CONSTR_TYPE_ATTR_DEFERRED = 11
125
+ CONSTR_TYPE_ATTR_IMMEDIATE = 12
126
+
127
+ OBJECT_TYPE_ACCESS_METHOD = 0
128
+ OBJECT_TYPE_AGGREGATE = 1
129
+ OBJECT_TYPE_AMOP = 2
130
+ OBJECT_TYPE_AMPROC = 3
131
+ OBJECT_TYPE_ATTRIBUTE = 4
132
+ OBJECT_TYPE_CAST = 5
133
+ OBJECT_TYPE_COLUMN = 6
134
+ OBJECT_TYPE_COLLATION = 7
135
+ OBJECT_TYPE_CONVERSION = 8
136
+ OBJECT_TYPE_DATABASE = 9
137
+ OBJECT_TYPE_DEFAULT = 10
138
+ OBJECT_TYPE_DEFACL = 11
139
+ OBJECT_TYPE_DOMAIN = 12
140
+ OBJECT_TYPE_DOMCONSTRAINT = 13
141
+ OBJECT_TYPE_EVENT_TRIGGER = 14
142
+ OBJECT_TYPE_EXTENSION = 15
143
+ OBJECT_TYPE_FDW = 16
144
+ OBJECT_TYPE_FOREIGN_SERVER = 17
145
+ OBJECT_TYPE_FOREIGN_TABLE = 18
146
+ OBJECT_TYPE_FUNCTION = 19
147
+ OBJECT_TYPE_INDEX = 20
148
+ OBJECT_TYPE_LANGUAGE = 21
149
+ OBJECT_TYPE_LARGEOBJECT = 22
150
+ OBJECT_TYPE_MATVIEW = 23
151
+ OBJECT_TYPE_OPCLASS = 24
152
+ OBJECT_TYPE_OPERATOR = 25
153
+ OBJECT_TYPE_OPFAMILY = 26
154
+ OBJECT_TYPE_POLICY = 27
155
+ OBJECT_TYPE_PUBLICATION = 28
156
+ OBJECT_TYPE_PUBLICATION_REL = 29
157
+ OBJECT_TYPE_ROLE = 30
158
+ OBJECT_TYPE_RULE = 31
159
+ OBJECT_TYPE_SCHEMA = 32
160
+ OBJECT_TYPE_SEQUENCE = 33
161
+ OBJECT_TYPE_SUBSCRIPTION = 34
162
+ OBJECT_TYPE_STATISTIC_EXT = 35
163
+ OBJECT_TYPE_TABCONSTRAINT = 36
164
+ OBJECT_TYPE_TABLE = 37
165
+ OBJECT_TYPE_TABLESPACE = 38
166
+ OBJECT_TYPE_TRANSFORM = 39
167
+ OBJECT_TYPE_TRIGGER = 40
168
+ OBJECT_TYPE_TSCONFIGURATION = 41
169
+ OBJECT_TYPE_TSDICTIONARY = 42
170
+ OBJECT_TYPE_TSPARSER = 43
171
+ OBJECT_TYPE_TSTEMPLATE = 44
172
+ OBJECT_TYPE_TYPE = 45
173
+ OBJECT_TYPE_USER_MAPPING = 46
174
+ OBJECT_TYPE_VIEW = 47
175
+
176
+ BOOL_EXPR_AND = 0
177
+ BOOL_EXPR_OR = 1
178
+ BOOL_EXPR_NOT = 2
179
+
180
+ BOOLEAN_TEST_TRUE = 0
181
+ BOOLEAN_TEST_NOT_TRUE = 1
182
+ BOOLEAN_TEST_FALSE = 2
183
+ BOOLEAN_TEST_NOT_FALSE = 3
184
+ BOOLEAN_TEST_UNKNOWN = 4
185
+ BOOLEAN_TEST_NOT_UNKNOWN = 5
186
+
187
+ AEXPR_OP = 0 # normal operator
188
+ AEXPR_OP_ANY = 1 # scalar op ANY (array)
189
+ AEXPR_OP_ALL = 2 # scalar op ALL (array)
190
+ AEXPR_DISTINCT = 3 # IS DISTINCT FROM - name must be "="
191
+ AEXPR_NOT_DISTINCT = 4 # IS NOT DISTINCT FROM - name must be "="
192
+ AEXPR_NULLIF = 5 # NULLIF - name must be "="
193
+ AEXPR_OF = 6 # IS [NOT] OF - name must be "=" or "<>"
194
+ AEXPR_IN = 7 # [NOT] IN - name must be "=" or "<>"
195
+ AEXPR_LIKE = 8 # [NOT] LIKE - name must be "~~" or "!~~"
196
+ AEXPR_ILIKE = 9 # [NOT] ILIKE - name must be "~~*" or "!~~*"
197
+ AEXPR_SIMILAR = 10 # [NOT] SIMILAR - name must be "~" or "!~"
198
+ AEXPR_BETWEEN = 11 # name must be "BETWEEN"
199
+ AEXPR_NOT_BETWEEN = 12 # name must be "NOT BETWEEN"
200
+ AEXPR_BETWEEN_SYM = 13 # name must be "BETWEEN SYMMETRIC"
201
+ AEXPR_NOT_BETWEEN_SYM = 14 # name must be "NOT BETWEEN SYMMETRIC"
202
+ AEXPR_PAREN = 15 # nameless dummy node for parentheses
203
+
204
+ TRANS_STMT_BEGIN = 0
205
+ TRANS_STMT_START = 1 # semantically identical to BEGIN
206
+ TRANS_STMT_COMMIT = 2
207
+ TRANS_STMT_ROLLBACK = 3
208
+ TRANS_STMT_SAVEPOINT = 4
209
+ TRANS_STMT_RELEASE = 5
210
+ TRANS_STMT_ROLLBACK_TO = 6
211
+ TRANS_STMT_PREPARE = 7
212
+ TRANS_STMT_COMMIT_PREPARED = 8
213
+ TRANS_STMT_ROLLBACK_PREPARED = 9
214
+
215
+ SUBLINK_TYPE_EXISTS = 0 # EXISTS(SELECT ...)
216
+ SUBLINK_TYPE_ALL = 1 # (lefthand) op ALL (SELECT ...)
217
+ SUBLINK_TYPE_ANY = 2 # (lefthand) op ANY (SELECT ...)
218
+ SUBLINK_TYPE_ROWCOMPARE = 3 # (lefthand) op (SELECT ...)
219
+ SUBLINK_TYPE_EXPR = 4 # (SELECT with single targetlist item ...)
220
+ SUBLINK_TYPE_MULTIEXPR = 5 # (SELECT with multiple targetlist items ...)
221
+ SUBLINK_TYPE_ARRAY = 6 # ARRAY(SELECT with single targetlist item ...)
222
+ SUBLINK_TYPE_CTE = 7 # WITH query (never actually part of an expression), for SubPlans only
223
+
224
+ LCS_NONE = 0 # no such clause - only used in PlanRowMark
225
+ LCS_FORKEYSHARE = 1 # FOR KEY SHARE
226
+ LCS_FORSHARE = 2 # FOR SHARE
227
+ LCS_FORNOKEYUPDATE = 3 # FOR NO KEY UPDATE
228
+ LCS_FORUPDATE = 4 # FOR UPDATE
229
+
230
+ AT_AddColumn = 0 # add column
231
+ AT_AddColumnRecurse = 1 # internal to commands/tablecmds.c
232
+ AT_AddColumnToView = 2 # implicitly via CREATE OR REPLACE VIEW
233
+ AT_ColumnDefault = 3 # alter column default
234
+ AT_DropNotNull = 4 # alter column drop not null
235
+ AT_SetNotNull = 5 # alter column set not null
236
+ AT_SetStatistics = 6 # alter column set statistics
237
+ AT_SetOptions = 7 # alter column set ( options )
238
+ AT_ResetOptions = 8 # alter column reset ( options )
239
+ AT_SetStorage = 9 # alter column set storage
240
+ AT_DropColumn = 10 # drop column
241
+ AT_DropColumnRecurse = 11 # internal to commands/tablecmds.c
242
+ AT_AddIndex = 12 # add index
243
+ AT_ReAddIndex = 13 # internal to commands/tablecmds.c
244
+ AT_AddConstraint = 14 # add constraint
245
+ AT_AddConstraintRecurse = 15 # internal to commands/tablecmds.c
246
+ AT_ReAddConstraint = 16 # internal to commands/tablecmds.c
247
+ AT_AlterConstraint = 17 # alter constraint
248
+ AT_ValidateConstraint = 18 # validate constraint
249
+ AT_ValidateConstraintRecurse = 19 # internal to commands/tablecmds.c
250
+ AT_ProcessedConstraint = 20 # pre-processed add constraint (local in parser/parse_utilcmd.c)
251
+ AT_AddIndexConstraint = 21 # add constraint using existing index
252
+ AT_DropConstraint = 22 # drop constraint
253
+ AT_DropConstraintRecurse = 23 # internal to commands/tablecmds.c
254
+ AT_ReAddComment = 24 # internal to commands/tablecmds.c
255
+ AT_AlterColumnType = 25 # alter column type
256
+ AT_AlterColumnGenericOptions = 26 # alter column OPTIONS (...)
257
+ AT_ChangeOwner = 27 # change owner
258
+ AT_ClusterOn = 28 # CLUSTER ON
259
+ AT_DropCluster = 29 # SET WITHOUT CLUSTER
260
+ AT_SetLogged = 30 # SET LOGGED
261
+ AT_SetUnLogged = 31 # SET UNLOGGED
262
+ AT_AddOids = 32 # SET WITH OIDS
263
+ AT_AddOidsRecurse = 33 # internal to commands/tablecmds.c
264
+ AT_DropOids = 34 # SET WITHOUT OIDS
265
+ AT_SetTableSpace = 35 # SET TABLESPACE
266
+ AT_SetRelOptions = 36 # SET (...) -- AM specific parameters
267
+ AT_ResetRelOptions = 37 # RESET (...) -- AM specific parameters
268
+ AT_ReplaceRelOptions = 38 # replace reloption list in its entirety
269
+ AT_EnableTrig = 39 # ENABLE TRIGGER name
270
+ AT_EnableAlwaysTrig = 40 # ENABLE ALWAYS TRIGGER name
271
+ AT_EnableReplicaTrig = 41 # ENABLE REPLICA TRIGGER name
272
+ AT_DisableTrig = 42 # DISABLE TRIGGER name
273
+ AT_EnableTrigAll = 43 # ENABLE TRIGGER ALL
274
+ AT_DisableTrigAll = 44 # DISABLE TRIGGER ALL
275
+ AT_EnableTrigUser = 45 # ENABLE TRIGGER USER
276
+ AT_DisableTrigUser = 46 # DISABLE TRIGGER USER
277
+ AT_EnableRule = 47 # ENABLE RULE name
278
+ AT_EnableAlwaysRule = 48 # ENABLE ALWAYS RULE name
279
+ AT_EnableReplicaRule = 49 # ENABLE REPLICA RULE name
280
+ AT_DisableRule = 50 # DISABLE RULE name
281
+ AT_AddInherit = 51 # INHERIT parent
282
+ AT_DropInherit = 52 # NO INHERIT parent
283
+ AT_AddOf = 53 # OF <type_name>
284
+ AT_DropOf = 54 # NOT OF
285
+ AT_ReplicaIdentity = 55 # REPLICA IDENTITY
286
+ AT_EnableRowSecurity = 56 # ENABLE ROW SECURITY
287
+ AT_DisableRowSecurity = 57 # DISABLE ROW SECURITY
288
+ AT_ForceRowSecurity = 58 # FORCE ROW SECURITY
289
+ AT_NoForceRowSecurity = 59 # NO FORCE ROW SECURITY
290
+ AT_GenericOptions = 60 # OPTIONS (...)
291
+ AT_AttachPartition = 61 # ATTACH PARTITION
292
+ AT_DetachPartition = 62 # DETACH PARTITION
293
+ AT_AddIdentity = 63 # ADD IDENTITY
294
+ AT_SetIdentity = 64 # SET identity column options
295
+ AT_DropIdentity = 65 # DROP IDENTITY
296
+ end