vitessio/vitess · error
unexpected table spec
Error message
unexpected table spec
What it means
ErrUnexpectedTableSpec indicates schemadiff received a sqlparser.TableSpec it does not expect or cannot handle. Create TABLE entity parsing expects a normal *sqlparser.TableSpec; alternative table constructs produce this sentinel error.
Source
Thrown at go/vt/schemadiff/errors.go:32
limitations under the License.
*/
package schemadiff
import (
"errors"
"fmt"
"strings"
"vitess.io/vitess/go/sqlescape"
"vitess.io/vitess/go/vt/sqlparser"
)
var (
ErrEntityTypeMismatch = errors.New("mismatched entity type")
ErrStrictIndexOrderingUnsupported = errors.New("strict index ordering is unsupported")
ErrUnexpectedDiffAction = errors.New("unexpected diff action")
ErrUnexpectedTableSpec = errors.New("unexpected table spec")
ErrExpectedCreateTable = errors.New("expected a CREATE TABLE statement")
ErrExpectedCreateView = errors.New("expected a CREATE VIEW statement")
)
type ImpossibleApplyDiffOrderError struct {
UnorderedDiffs []EntityDiff
ConflictingDiffs []EntityDiff
}
func (e *ImpossibleApplyDiffOrderError) Error() string {
var b strings.Builder
conflictingStatements := e.ConflictingStatements()
fmt.Fprintf(&b, "no valid applicable order for diffs. %d diffs found conflicting:", len(conflictingStatements))
for _, s := range conflictingStatements {
b.WriteString("\n")
b.WriteString(s)
}
return b.String()View on GitHub (pinned to 01a25a7d17)
Solutions
- Use full explicit CREATE TABLE statements (columns and constraints spelled out)
- Pre-process the schema to expand CREATE TABLE ... LIKE into concrete definitions
- Check the statement parses to a standard TableSpec before passing it to schemadiff
Example fix
// before
entity, err := schemadiff.NewCreateTableEntityFromSQL("CREATE TABLE t2 LIKE t1") // unexpected table spec
// after
entity, err := schemadiff.NewCreateTableEntityFromSQL("CREATE TABLE t2 (id INT PRIMARY KEY)") Defensive patterns
Strategy: validation
Validate before calling
stmt, err := sqlparser.Parse("CREATE TABLE t2 LIKE t1")
if _, ok := stmt.(*sqlparser.CreateTable); !ok || likeSpeced(stmt) {
// expand into explicit column definitions before schemadiff
} Try / catch
if err != nil {
if errors.Is(err, schemadiff.ErrUnexpectedTableSpec) {
// reject or expand the statement
}
} Prevention
- Avoid CREATE TABLE ... LIKE / AS SELECT in managed schemas
- Spell out full column definitions
- Lint schema DDL before feeding schemadiff
When it happens
Trigger: Calling NewCreateTableEntityFromSQL or getCreateTableStatement on a CREATE TABLE whose parsed spec type is not the expected *sqlparser.TableSpec (e.g. CREATE TABLE ... LIKE or other unsupported forms).
Common situations: Feeding CREATE TABLE ... AS SELECT or CREATE TABLE ... LIKE statements into schemadiff instead of full column-definition CREATE TABLEs.
Related errors
- unexpected diff action
- expected a CREATE TABLE statement
- found no possible unique key on `%s`
- BeforeSchema differs
- AfterSchema differs
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/039467d66206e705.
Report an issue: GitHub.