gotro icon indicating copy to clipboard operation
gotro copied to clipboard

Error when creating a postgresql table

Open antonsofyan opened this issue 5 months ago • 0 comments

There is an error when running the CreateBaseTable function in the postgreSQL package (D/Pg), where the table is created successfully but the index fails, because the DDL process did not return the affected rows.

The following is the code that is executed:

package main

import (
	"github.com/kokizzu/gotro/D/Pg"
)

func main() {
	pg_conn := Pg.NewConn(`db`, `pass`)
	pg_conn.CreateBaseTable(`users`, `users`)
}

there is an error here

ra, _ := tx.DoExec(query).RowsAffected()
if ra > 0 {
    // will never get in here
}

maybe it should be like this

_, err := tx.DoExec(query).RowsAffected()
if err == nil {
    // create index
}

Terima kasih Pak @kokizzu :)

antonsofyan avatar Aug 04 '25 23:08 antonsofyan