New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: add notice for Alter TYPE ADD VALUE IF NOT EXIST command #52534
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,25 +254,9 @@ func (desc *MutableTypeDescriptor) IsNew() bool { | |
} | ||
|
||
// AddEnumValue adds an enum member to the type. | ||
// AddEnumValue assumes that the type is an enum, and that the new value | ||
// doesn't exist already in the enum. | ||
func (desc *MutableTypeDescriptor) AddEnumValue(node *tree.AlterTypeAddValue) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the comment here now to say that "AddEnumValue assumes that the type is an enum, and that the new value doesn't exist already in the enum" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated comment, i will make sure to do such descriptive code comments in future contributions. |
||
if desc.Kind != descpb.TypeDescriptor_ENUM { | ||
return pgerror.Newf(pgcode.WrongObjectType, "%q is not an enum", desc.Name) | ||
} | ||
// See if the value already exists in the enum or not. | ||
found := false | ||
for _, member := range desc.EnumMembers { | ||
if member.LogicalRepresentation == node.NewVal { | ||
found = true | ||
break | ||
} | ||
} | ||
if found { | ||
if node.IfNotExists { | ||
return nil | ||
} | ||
return pgerror.Newf(pgcode.DuplicateObject, "enum label %q already exists", node.NewVal) | ||
} | ||
|
||
getPhysicalRep := func(idx int) []byte { | ||
if idx < 0 || idx >= len(desc.EnumMembers) { | ||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last nit -- don't also remove the comment that actually tells what the function does!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed