Content-Length: 414031 | pFad | http://github.com/sqlancer/sqlancer/commit/3fe905a4294e7bbb0dcbf1e9d8d6cfa5aa1c0a28

BB Add support for Alter View Rename Column in Postgres v13 · sqlancer/sqlancer@3fe905a · GitHub
Skip to content

Commit 3fe905a

Browse files
committed
Add support for Alter View Rename Column in Postgres v13
1 parent 3d9a5cc commit 3fe905a

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

src/sqlancer/postgres/gen/PostgresAlterTableGenerator.java

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected enum Action {
4848
SET_LOGGED_UNLOGGED, //
4949
NOT_OF, //
5050
OWNER_TO, //
51-
REPLICA_IDENTITY
51+
REPLICA_IDENTITY, ALTER_VIEW_RENAME_COLUMN // RENAME COLUMN old_name TO new_name (for views)
5252
}
5353

5454
public PostgresAlterTableGenerator(PostgresTable randomTable, PostgresGlobalState globalState,
@@ -98,6 +98,20 @@ public List<Action> getActions(ExpectedErrors errors) {
9898
// make it more likely that the ALTER TABLE succeeds
9999
action = Randomly.subset(Randomly.smallNumber(), Action.values());
100100
}
101+
102+
// If this is a view, only allow view-compatible operations
103+
if (randomTable.isView()) {
104+
// Remove all table-specific operations for views
105+
action.removeIf(a -> a != Action.ALTER_VIEW_RENAME_COLUMN);
106+
// If no view operations remain, add the rename column action
107+
if (action.isEmpty()) {
108+
action.add(Action.ALTER_VIEW_RENAME_COLUMN);
109+
}
110+
} else {
111+
// Remove view-specific actions if this is a table
112+
action.remove(Action.ALTER_VIEW_RENAME_COLUMN);
113+
}
114+
101115
if (randomTable.getColumns().size() == 1) {
102116
action.remove(Action.ALTER_TABLE_DROP_COLUMN);
103117
}
@@ -120,14 +134,24 @@ public SQLQueryAdapter generate() {
120134
int i = 0;
121135
List<Action> action = getActions(errors);
122136
StringBuilder sb = new StringBuilder();
123-
sb.append("ALTER TABLE ");
124-
if (Randomly.getBoolean()) {
125-
sb.append(" ONLY");
126-
errors.add("cannot use ONLY for foreign key on partitioned table");
137+
138+
// Check if we're dealing with a view operation
139+
boolean isViewOperation = action.contains(Action.ALTER_VIEW_RENAME_COLUMN);
140+
141+
if (isViewOperation) {
142+
sb.append("ALTER VIEW ");
143+
} else {
144+
sb.append("ALTER TABLE ");
145+
if (Randomly.getBoolean()) {
146+
sb.append(" ONLY");
147+
errors.add("cannot use ONLY for foreign key on partitioned table");
148+
}
127149
}
150+
128151
sb.append(" ");
129152
sb.append(randomTable.getName());
130153
sb.append(" ");
154+
131155
for (Action a : action) {
132156
if (i++ != 0) {
133157
sb.append(", ");
@@ -364,6 +388,17 @@ public SQLQueryAdapter generate() {
364388
errors.add("cannot use invalid index");
365389
}
366390
break;
391+
case ALTER_VIEW_RENAME_COLUMN:
392+
sb.append("RENAME COLUMN ");
393+
PostgresColumn columnToRename = randomTable.getRandomColumn();
394+
sb.append(columnToRename.getName());
395+
sb.append(" TO ");
396+
sb.append("new_" + columnToRename.getName() + "_" + r.getInteger(1, 1000));
397+
errors.add("column does not exist");
398+
errors.add("column name already exists");
399+
errors.add("cannot rename column of view");
400+
errors.add("permission denied");
401+
break;
367402
default:
368403
throw new AssertionError(a);
369404
}

src/sqlancer/postgres/gen/PostgresSetGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private enum ConfigurationOption {
112112
JIT("jit", (r) -> Randomly.fromOptions(1, 0)),
113113
JOIN_COLLAPSE_LIMIT("join_collapse_limit", (r) -> r.getInteger(1, Integer.MAX_VALUE)),
114114
PARALLEL_LEADER_PARTICIPATION("parallel_leader_participation", (r) -> Randomly.fromOptions(1, 0)),
115-
FORCE_PARALLEL_MODE("force_parallel_mode", (r) -> Randomly.fromOptions("off", "on", "regress")),
115+
// FORCE_PARALLEL_MODE("force_parallel_mode", (r) -> Randomly.fromOptions("off", "on", "regress")),
116116
PLAN_CACHE_MODE("plan_cache_mode",
117117
(r) -> Randomly.fromOptions("auto", "force_generic_plan", "force_custom_plan"));
118118

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/sqlancer/sqlancer/commit/3fe905a4294e7bbb0dcbf1e9d8d6cfa5aa1c0a28

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy