第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

盡管字符串是有效的 UTF8,但字節(jié)序列無效

盡管字符串是有效的 UTF8,但字節(jié)序列無效

Go
楊__羊羊 2023-06-19 17:23:07
我正在嘗試將 txt 寫入 postgres 批量導(dǎo)入器。該代碼當(dāng)前崩潰,因為應(yīng)該插入到 postgres 的字符串不是有效的 UTF8:pq: invalid byte sequence for encoding UTF8: 0x00在我的代碼中,我正在檢查字符串是否為有效的 UTF8。我錯過了什么?代碼:for {        line, more := <-lineChannel        splitLine := strings.SplitN(line, ":", 2)        if len(splitLine) == 2 {            if utf8.Valid([]byte(splitLine[0])) && utf8.Valid([]byte(splitLine[1])) {                lineCount++                _, err = stmt.Exec(splitLine[0], splitLine[1])                if lineCount%int64(copySize) == 0 {                    _, err = stmt.Exec()                    if err != nil {                        log.Fatal("Failed at stmt.Exec", err)                    }                    err = stmt.Close()                    if err != nil {                        log.Fatal("Failed at stmt.Close", err)                    }                    err = txn.Commit()                    if err != nil {                        log.Fatal("failed at txn.Commit", err)                    }                    txn, err = db.Begin()                    if err != nil {                        log.Fatal("failed at db.Begin", err)                    }                    stmt, err = txn.Prepare(pq.CopyIn("pwned", "username", "password"))                    if err != nil {                        log.Fatal("failed at txn.Prepare", err)                    }                    if lineCount%(int64(copySize)*10) == 0 {                        log.Printf("Inserted %v lines", lineCount)                    }                }                if err != nil {                    log.Println("error:", splitLine[0], splitLine[1])                    log.Fatal(err)                }            }編輯:出錯的行:字節(jié)[]:[116 109 97 105 108 46 99 111 109 58 104 117 115 104 112 117 112 112 105 101 115 108 111 118 101]線:username@hotmail.whatever:hushpuppieslove分割線[0] + 分割線[1]:username@hotmail.whatever hushpuppieslove
查看完整描述

1 回答

?
白衣非少年

TA貢獻1155條經(jīng)驗 獲得超0個贊

0x00 是空字符,postgres 不允許在字符串中使用。從文檔:

NULL (0) 字符是不允許的,因為文本數(shù)據(jù)類型不能存儲此類字節(jié)。

您需要刪除空字符。


查看完整回答
反對 回復(fù) 2023-06-19
  • 1 回答
  • 0 關(guān)注
  • 151 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號