MCPcopy Create free account
hub / github.com/PostHog/duckgres / encodeBinary

Function encodeBinary

server/types.go:257–303  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

255// encodeBinary encodes a value in PostgreSQL binary format
256// Returns the encoded bytes, or nil if the value should be sent as NULL
257func 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
305func encodeBool(v interface{}) []byte {
306 var b bool

Callers 5

TestEncodeBinaryFunction · 0.85
TestEncodeBinaryJSONFunction · 0.85
handleCopyOutBinaryMethod · 0.85
encodeArrayFunction · 0.85

Calls 15

encodeArrayFunction · 0.85
encodeBoolFunction · 0.85
encodeInt2Function · 0.85
encodeInt4Function · 0.85
encodeInt8Function · 0.85
encodeFloat4Function · 0.85
encodeFloat8Function · 0.85
encodeNumericFunction · 0.85
encodeDateFunction · 0.85
encodeTimestampFunction · 0.85
encodeTimeFunction · 0.85
encodeIntervalFunction · 0.85

Tested by 2

TestEncodeBinaryFunction · 0.68
TestEncodeBinaryJSONFunction · 0.68