I found a PostgreSQL bug report requesting removal of the restriction. Here's the final reply:
Franklin Schmidt wrote: > I agree that storing 0x00 in a UTF8 string is weird, but I am > converting a huge database to postgres, and in a huge database, weird > things happen. Using bytea for a text field just because one in a > million records has a 0x00 doesn't make sense to me. I did hack > around it in my conversion code to remove the 0x00 but I expect that > anyone else who tries converting a big database to postgres will also > confront this issue. That's the right solution. If you have 0x00 bytes in your text fields, you're much better off cleaning them away anyway, than trying to work around them. -Heikki Linnakangas https://www.postgresql.org/message-id/200712170734.lBH7YdG9034458%40wwwmaster.postgresql.org I also found a possible related discussion about supporting \u0000 in JSON values [1]. PostgreSQL tried to support it but had to remove that support because it caused ambiguity. https://www.postgresql.org/message-id/[email protected] On Wednesday, May 31, 2017 at 8:27:49 PM UTC-4, Jon Dufresne wrote: > > On Mon, May 15, 2017 at 10:30 AM, Tim Chase <[email protected] > <javascript:>> wrote: > >> On 2017-05-15 08:54, Tim Graham wrote: >> > Does anyone know of a use case for using null bytes in >> > CharField/TextField? >> >> Is this not what BinaryField is for? It would seem to me that >> attempting to store binary NULL bytes in a CharField/TextField should >> result in an error condition. >> > > The null byte is also a valid Unicode code point [0]. > > I guess I'm a bit surprised that a valid code point can't be stored in a > PostgreSQL text column. This does appear to be documented for the char(int) > string function [1], although without justification. > > > The NULL (0) character is not allowed because text data types cannot > store such bytes. > > I'm curious behind PostgreSQL's decision to prohibit this code point. If > anyone has additional information to share on their reason, please pass it > along. > > > [0] http://www.fileformat.info/info/unicode/char/0000/index.htm > [1] https://www.postgresql.org/docs/current/static/functions-string.html > > Cheers > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/450da309-c2af-43a9-8026-51d23994f8c9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
