Skip to content

Commit

Permalink
Fix primary key constraint for nullable keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ryannedolan committed Jun 21, 2024
1 parent c3fa16a commit 2ec1a0d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public SqlNode visit(SqlCall call) {
* Implements a CREATE TABLE...WITH... DDL statement.
*
* N.B. the following magic:
* - field 'KEY' is treated as a PRIMARY KEY
* - non-nullable field 'KEY' is treated as a PRIMARY KEY
*/
class ConnectorImplementor implements ScriptImplementor {
private final String database;
Expand All @@ -192,7 +192,8 @@ public void implement(SqlWriter w) {
(new CompoundIdentifierImplementor(database, name)).implement(w);
SqlWriter.Frame frame1 = w.startList("(", ")");
(new RowTypeSpecImplementor(rowType)).implement(w);
if (rowType.getField("KEY", true, false) != null) {
RelDataTypeField key = rowType.getField("KEY", true, false);
if (key != null && key.getType().isNullable() == false) {
w.sep(",");
w.literal("PRIMARY KEY (KEY) NOT ENFORCED");
}
Expand Down

0 comments on commit 2ec1a0d

Please sign in to comment.