encodeBinary encodes a value in PostgreSQL binary format Returns the encoded bytes, or nil if the value should be sent as NULL
(v interface{}, oid int32)
| 255 | // encodeBinary encodes a value in PostgreSQL binary format |
| 256 | // Returns the encoded bytes, or nil if the value should be sent as NULL |
| 257 | func encodeBinary(v interface{}, oid int32) []byte { |
| 258 | if v == nil { |
| 259 | return nil |
| 260 | } |
| 261 | |
| 262 | // Check if this is an array OID |
| 263 | if elemOID, ok := arrayElementOIDs[oid]; ok { |
| 264 | return encodeArray(v, elemOID) |
| 265 | } |
| 266 | |
| 267 | switch oid { |
| 268 | case OidBool: |
| 269 | return encodeBool(v) |
| 270 | case OidInt2: |
| 271 | return encodeInt2(v) |
| 272 | case OidInt4: |
| 273 | return encodeInt4(v) |
| 274 | case OidInt8: |
| 275 | return encodeInt8(v) |
| 276 | case OidFloat4: |
| 277 | return encodeFloat4(v) |
| 278 | case OidFloat8: |
| 279 | return encodeFloat8(v) |
| 280 | case OidNumeric: |
| 281 | return encodeNumeric(v) |
| 282 | case OidDate: |
| 283 | return encodeDate(v) |
| 284 | case OidTimestamp, OidTimestamptz: |
| 285 | return encodeTimestamp(v) |
| 286 | case OidTime: |
| 287 | return encodeTime(v) |
| 288 | case OidInterval: |
| 289 | return encodeInterval(v) |
| 290 | case OidUUID: |
| 291 | return encodeUUID(v) |
| 292 | case OidBytea: |
| 293 | return encodeBytea(v) |
| 294 | case OidJSON, OidJSONB: |
| 295 | // The Go DuckDB driver deserializes JSON columns into native Go types |
| 296 | // (e.g., JSON string "hello" → Go string hello, without quotes). |
| 297 | // Re-serialize to JSON text before sending on the wire. |
| 298 | return encodeJSON(v) |
| 299 | default: |
| 300 | // For text, varchar, and other types, encode as text bytes |
| 301 | return encodeText(v) |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | func encodeBool(v interface{}) []byte { |
| 306 | var b bool |