JetBrains / JetBrains/Exposed

Null characters in Postgres

Open
#536 1 comment 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

Postgres doesn't support null-characters in strings (text, char, varchar). Though Postrgres is advertised to support UTF-8 where zero code point is a valid one. H2, sqlite, mysql support nulls, by the way.
Postgres driver just throws `PSQLException: ERROR: invalid byte sequence for encoding "UTF8": 0x00` in this case. Exposed is one level above above the abstraction of driver hence it seems reasonable to protect the user from such fail for example with help of [MUTF-8](https://en.wikipedia.org/wiki/UTF-8#Modified_UTF-8), just by replacing all output null characters with `0xC0, 0x80`. The practice of implicit use of slight mods of UTF-8 like MUTF-8 and WTF-8 is pretty common.
It's a kind of enhancement, I guess. Is it even possible? May relate to #264 and also depend on splitting into per-dialect modules.

Minified example if needed:
```kotlin
object Tests: IntIdTable("test") {
val str = text("str")
}

fun main(args: Array) {
val dbPort = 5432
val dbName = "testdb"
val db = Database.connect("jdbc:postgresql://localhost:$dbPort/$dbName", driver = "org.postgresql.Driver",
user = "test", password = "test")

transaction(db) {
SchemaUtils.create(Tests)

Tests.insert {
it[str] = "\u0000"
}
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.