GORM Playground Link

https://github.com/go-gorm/playground/pull/478

Description

My code is below.

// mysql
// CREATE TABLE table_a (a_name CHAR(8) NOT NULL)

var data struct {
  AName string
}
db = db.Table("table_a AS a")
db.Create(&data)

It will Execute

INSERT INTO table_a AS a (`a_name`) VALUES ('') -- sql 1

And return an error.

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS a (`a_name`) VALUES (?)' at line 1

I want

INSERT INTO table_a (`a_name`) VALUES ('')  -- sql 2

It looks like the table alias was added to the INSERT statement. But sql 1 works well in postgres. Probably "INSERT table AS" syntax is only supported by postgres.

Comment From: a631807682

Table is used to specify the table name, will not parse sql to do anything, you should use clause.Table to specify alias.