Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit 1cd2662

Browse files
gzsomborlunny
authored andcommitted
Fix exporting into Postgres, problems: (#1186)
* UUID and BOOL type shouldn't have a length field * Incorrect quoting cause that the column names are selected instead of the column values
1 parent a8f0a71 commit 1cd2662

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

dialect_postgres.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ func (db *postgres) SqlType(c *core.Column) string {
822822
case core.NVarchar:
823823
res = core.Varchar
824824
case core.Uuid:
825-
res = core.Uuid
825+
return core.Uuid
826826
case core.Blob, core.TinyBlob, core.MediumBlob, core.LongBlob:
827827
return core.Bytea
828828
case core.Double:
@@ -834,6 +834,10 @@ func (db *postgres) SqlType(c *core.Column) string {
834834
res = t
835835
}
836836

837+
if strings.EqualFold(res, "bool") {
838+
// for bool, we don't need length information
839+
return res
840+
}
837841
hasLen1 := (c.Length > 0)
838842
hasLen2 := (c.Length2 > 0)
839843

engine.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
481481
}
482482

483483
cols := table.ColumnsSeq()
484-
colNames := dialect.Quote(strings.Join(cols, dialect.Quote(", ")))
484+
colNames := engine.dialect.Quote(strings.Join(cols, engine.dialect.Quote(", ")))
485+
destColNames := dialect.Quote(strings.Join(cols, dialect.Quote(", ")))
485486

486487
rows, err := engine.DB().Query("SELECT " + colNames + " FROM " + engine.Quote(table.Name))
487488
if err != nil {
@@ -496,7 +497,7 @@ func (engine *Engine) dumpTables(tables []*core.Table, w io.Writer, tp ...core.D
496497
return err
497498
}
498499

499-
_, err = io.WriteString(w, "INSERT INTO "+dialect.Quote(table.Name)+" ("+colNames+") VALUES (")
500+
_, err = io.WriteString(w, "INSERT INTO "+dialect.Quote(table.Name)+" ("+destColNames+") VALUES (")
500501
if err != nil {
501502
return err
502503
}

0 commit comments

Comments
 (0)