-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Stings vs. bites weirdness #4312
Copy link
Copy link
Closed
Description
I have the following schema:
CREATE TABLE IF NOT EXISTS loadgen.comments (
photoID BYTES,
commentID BYTES DEFAULT EXPERIMENTAL_UUID_V4(),
userID INT,
message STRING,
timestamp TIMESTAMP,
PRIMARY KEY (photoID, commentID)
);
When trying to insert into the table with the following go code, it fails:
const insertSQL = `
INSERT INTO loadgen.comments VALUES ($1::bytea, DEFAULT, $2, $3, NOW());
`
const minMessageLen = 32
const maxMessageLen = 1024
message := randStringBytes(minMessageLen + rand.Intn(maxMessageLen-minMessageLen))
photoID := []byte{'a', 'b', 'c'}
if _, err := tx.Exec(insertSQL, photoID, authorID, message); err != nil {
log.Infof("insert into photos failed: %s", err)
return err
}
The failure is: pq: invalid cast: parameter -> BYTEA
It works if I don't add the cast. However, when doing a select:
SELECT commentID, userID, message, timestamp FROM loadgen.comments WHERE photoID = $1::bytea ORDER BY timestamp LIMIT 100
If I DON'T add the ::bytea cast, it fails with: pq: unsupported comparison operator: <bytes> = <string>
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels