Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/docs/ops/targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ For all other vector types, we map them to `jsonb` columns.

:::

:::info U+0000 (NUL) characters in strings

U+0000 (NUL) is a valid character in Unicode, but Postgres has a limitation that strings (including `text`-like types and strings in `jsonb`) cannot contain them.
CocoIndex automatically strips U+0000 (NUL) characters from strings before exporting to Postgres. For example, if you have a string `"Hello\0World"`, it will be exported as `"HelloWorld"`.

:::

#### Spec

The spec takes the following fields:
Expand Down
26 changes: 16 additions & 10 deletions src/ops/targets/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn bind_value_field<'arg>(
builder.push_bind(&**v);
}
BasicValue::Str(v) => {
builder.push_bind(&**v);
builder.push_bind(utils::str_sanitize::ZeroCodeStrippedEncode(v.as_ref()));
}
BasicValue::Bool(v) => {
builder.push_bind(v);
Expand Down Expand Up @@ -82,7 +82,9 @@ fn bind_value_field<'arg>(
builder.push_bind(v);
}
BasicValue::Json(v) => {
builder.push_bind(sqlx::types::Json(&**v));
builder.push_bind(sqlx::types::Json(
utils::str_sanitize::ZeroCodeStrippedSerialize(&**v),
));
}
BasicValue::Vector(v) => match &field_schema.value_type.typ {
ValueType::Basic(BasicValueType::Vector(vs)) if convertible_to_pgvector(vs) => {
Expand All @@ -104,20 +106,24 @@ fn bind_value_field<'arg>(
}
},
BasicValue::UnionVariant { .. } => {
builder.push_bind(sqlx::types::Json(TypedValue {
t: &field_schema.value_type.typ,
v: value,
}));
builder.push_bind(sqlx::types::Json(
utils::str_sanitize::ZeroCodeStrippedSerialize(TypedValue {
t: &field_schema.value_type.typ,
v: value,
}),
));
}
},
Value::Null => {
builder.push("NULL");
}
v => {
builder.push_bind(sqlx::types::Json(TypedValue {
t: &field_schema.value_type.typ,
v,
}));
builder.push_bind(sqlx::types::Json(
utils::str_sanitize::ZeroCodeStrippedSerialize(TypedValue {
t: &field_schema.value_type.typ,
v,
}),
));
}
};
Ok(())
Expand Down
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod db;
pub mod fingerprint;
pub mod immutable;
pub mod retryable;
pub mod str_sanitize;
pub mod yaml_ser;
Loading
Loading