#40527 Fix false "Invalid column reference" error for UNSIGNED type modifier in CREATE TABLE#40708
Conversation
…MKnownRuleNames and refining default value expression logic in SQLQueryColumnSpec.
|
@E1izabeth |
E1izabeth
left a comment
There was a problem hiding this comment.
You've correctly found the root cause of the issue. However, the fix is masking the problem instead of fixing the root cause. So, we can not accept the proposed solution.
Let me solve again. |
…MKnownRuleNames and refining default value expression logic in SQLQueryColumnSpec.
…e for DDL column type modifiers
…e for DDL column type modifiers
| for (STMTreeNode child : node.findChildrenOfName(STMKnownRuleNames.typeModifier)) { | ||
| if (typeName != null) { | ||
| typeName = typeName + " " + child.getTextContent(); | ||
| } | ||
| } |
There was a problem hiding this comment.
I don't like this change.
- Are we sure that introducing any amount of actual-identifiers as
typeModifierwon't effectively consume any not-yet-covered keywords, turning it into nonsense? - Having the above, are we sure that type name construction by concatenation with a modifier won't break constraint expression analysis in terms of types?
- Consider such a line:
columnName customTypeName someDbSpecificModifiers CHECK (columnName.compositeField < 10)
HavingsomeDbSpecificModifierstreated as part of thecustomTypeNamewill break the composite type lookup and thus breakcompositeFieldcompletion and validation.
The solution I see is to add type modifiers to the dialect and dynamically bring those constants into the grammar. You can take a look at how it's done with knownIdentifierQuotes.
There was a problem hiding this comment.
I will update again.
Thanks
Closes: #40527
Summary
UNSIGNEDandZEROFILLin DDL statements (e.g.CREATE TABLE test (id INT UNSIGNED NOT NULL))typeModifiergrammar rule incolumnDefinitionto accept dialect-specific type modifiers between the data type and constraintsDEFAULTkeyword mandatory indefaultClauseto resolve grammar ambiguity between type modifiers and default value expressionstypeModifierinLSMInspectionsfor proper autocompletion and syntax classificationProblem
In the SQL script editor,
UNSIGNEDis underlined with the error "Invalid column reference" in DDL queries:How to test
CREATE TABLE test_table (test_table_id INT UNSIGNED NOT NULL, test_name VARCHAR(10) NOT NULL);UNSIGNEDis not underlined with "Invalid column reference"CREATE TABLE test_table (col1 INT DEFAULT 5 NOT NULL);still works correctly (default value recognized)ALTER TABLE test_table ADD COLUMN col2 BIGINT UNSIGNED NOT NULL;does not show the error