Skip to content

Commit d6cc8a6

Browse files
authored
Merge pull request #1246 from Dwolla/more-completions-for-main
Forward-port new Completions
2 parents 262f52a + 6012d6e commit d6cc8a6

File tree

4 files changed

+130
-61
lines changed

4 files changed

+130
-61
lines changed

modules/core/shared/src/main/scala/data/Completion.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,37 @@ object Completion {
7373
case object DropPolicy extends Completion
7474
case object Comment extends Completion
7575
case object Analyze extends Completion
76+
case object AlterDefaultPrivileges extends Completion
77+
case object GrantRole extends Completion
78+
case object RevokeRole extends Completion
79+
7680
// more ...
7781

82+
// weird Redshift variations
83+
84+
/**
85+
* This is a variation on the protocol included to better support Redshift. Redshift
86+
* doesn't return a count for a <code>SELECT</code> statement. The
87+
* [[https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-COMMANDCOMPLETE protocol documentation]]
88+
* appears to say it should:
89+
*
90+
* <blockquote>For a <code>SELECT</code> or <code>CREATE TABLE AS</code> command, the tag is <code>SELECT rows</code> where <code>rows</code> is the number of rows retrieved.</blockquote>
91+
*
92+
* but comments in the [[https://github.com/pgjdbc/pgjdbc/blob/5d1f2e8cd399cedfdee86728f9044c0e32d74129/pgjdbc/src/main/java/org/postgresql/core/CommandCompleteParser.java#L37-L44 JDBC driver]]
93+
* state
94+
*
95+
* <blockquote>
96+
* Parses <code>CommandComplete (B)</code> message.
97+
* Status is in the format of <code>COMMAND OID ROWS</code> where both <code>OID</code> and <code>ROWS</code> are optional
98+
* and <code>COMMAND</code> can have spaces within it, like <code>CREATE TABLE</code>.
99+
* </blockquote>
100+
*
101+
* so clients should probably be prepared to handle this.
102+
*
103+
* Practically speaking, true Postgres servers do return row counts, but Redshift does not.
104+
*/
105+
case object SelectWithoutCount extends Completion
106+
78107
/**
79108
* Instead of crashing (which breaks the protocol and hangs everything) let's allow for unknown
80109
* completion messages and print out a stacktrace on construction.

modules/core/shared/src/main/scala/net/message/CommandComplete.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,14 @@ object CommandComplete {
112112
case "ALTER POLICY" => apply(Completion.AlterPolicy)
113113
case "DROP POLICY" => apply(Completion.DropPolicy)
114114
case "ANALYZE" => apply(Completion.Analyze)
115+
case "ALTER DEFAULT PRIVILEGES" => apply(Completion.AlterDefaultPrivileges)
116+
case "GRANT ROLE" => apply(Completion.GrantRole)
117+
case "REVOKE ROLE" => apply(Completion.RevokeRole)
115118
// more .. fill in as we hit them
116119

120+
// weird Redshift variations
121+
case "SELECT" => apply(Completion.SelectWithoutCount)
122+
117123
case s => apply(Completion.Unknown(s))
118124
}
119125

0 commit comments

Comments
 (0)