doudu8291 2018-03-28 11:26
浏览 408

数据更改时自动更新PostgreSQL

I have the remote database which is in PostgreSQL and I have inserted all the tables with their data in my local database, but I can't figure out how to detect any changes from the remote database to be updated in my local database.

the table from the remote database postgres is users the table from the local database mysql is users

func Searching() {
    postgresqlusers, _ := GetUsersPostgres()
    mysqlusers, _ := GetUsersMysql()
    for _, valuepostgres := range postgresqlusers {
        if len(mysqlusers) == 0 {
            _, err := db.Exec("insert into user values(?,?,?)", valuepostgres.User_Id, valuepostgres.Uid, valuepostgres.Phone)
            if err != nil {
                fmt.Println(len(mysqlusers))
            }
        }
        for _, valuemysql := range mysqlusers {
            if valuepostgres.User_Id != valuemysql.User_Id {
                _, err := db.Exec("insert into user values(?,?,?)", valuepostgres.User_Id, valuepostgres.Uid, valuepostgres.Phone)
                if err != nil {
                    fmt.Println("data inserted successufly")
                }
            }
        }
    }
}

so both have the same structure, I made a script for the insertion with Go but I am stuck at updating changes automatically

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 聚类分析或者python进行数据分析
    • ¥15 如何用visual studio code实现html页面
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?