Skip to content

The column type DECIMAL(20,0) is restored incorrectly as DECIMAL #310

@kennytm

Description

@kennytm

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
package main

import (
	"fmt"
	"github.com/pingcap/parser"
	"github.com/pingcap/parser/format"
	_ "github.com/pingcap/tidb/types/parser_driver"
	"strings"
)

func main() {
	p := parser.New()
	nodes, _ := p.ParseOneStmt(`
		create table precise_types (
			c DECIMAL(20,0) NOT NULL,
			d DOUBLE(20,0) NOT NULL
		);
	`, "", "")

	var s strings.Builder
	ctx := format.NewRestoreCtx(format.DefaultRestoreFlags, &s)
	nodes.Restore(ctx)

	fmt.Println(s.String())
}
  1. What did you expect to see?

Prints

CREATE TABLE `precise_types` (`c` DECIMAL(20) NOT NULL,`d` DOUBLE(20,0) NOT NULL)
  1. What did you see instead?

The precision is just directly omitted.

CREATE TABLE `precise_types` (`c` DECIMAL NOT NULL,`d` DOUBLE NOT NULL)
  1. What version of TiDB SQL Parser are you using?

master (366172d)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions