These questions are really more for Thomas, but since he is (mostly) on vacation I will try to answer, and he can correct any mistakes. As you have discovered, the current behavior for entering quoted text into H2 is to treat it as pairs of hex characters encoding single bytes, no '0x' prefix needed.
On Jul 22, 10:23 am, kensystem <[email protected]> wrote: > 1) Should BYTEA columns accept ASCII input if quoted? [...] > Can it be changed to accept this on presumption that the string is an > ASCII one? I believe this is accepted by PG and some others. Probably not, for several good reasons. One: Adding ASCII input opens things up for ambiguity. Does 'FACE' mean the bytes 0xFACE (2 bytes) or the ASCII bytes (4 bytes)? What about NULL & unprintable characters? What about foreign languages -- some keyboards may not even have the standard US-ASCII keys on them? Two: Redundancy. The functions UTF8TOSTRING(bytes) and STRINGTOUTF8 (string) already exist to convert text to raw bytes. See: http://www.h2database.com/html/functions.html#stringtoutf8 This should be the preferred way to store text as bytes. Thomas could add a function to convert bytes to/from arbitrary text encodings, but it is very easy to do this in java or roll your own user-defined function to do it. Three: Performance. Parsing text as hex characters is very, very fast, and is safe against the complexities of character sets & encodings. US-ASCII isn't suitable for international use (as noted above). This is why UTF-8 & UTF-16 are replacing them; the catch is that they are much, much more complicated to parse, and you don't know how long the byte string is until you do. > 2) INSERT INTO registry (val) VALUES ('12345') which is considered hex > would be legal (even if missing the leading 0x) equivalent to 012345 > (0x012345) I suspect this can be changed without too much effort, although it will mean you have to read the entire string in to memory to check length. This could pose problems for very long byte strings, such as BLOBs encoded in an SQL script. > 3) INSERT INTO registry (val) VALUES ('0x012345') throws: > Hexadecimal string contains non-hex character: 0x012345 This is already in the Roadmap: http://www.h2database.com/html/roadmap.html If other people request it, it will get bumped up in priority. > 4) (I don't know if this should be accepted) INSERT INTO registry > (val) VALUES (0x012345) throws: > Hexadecimal string with odd number of characters: 74565; See answer to (2). Cheers, Bob McGee --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "H2 Database" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/h2-database?hl=en -~----------~----~----~----~------~----~------~--~---
