4 ms·
Can someone explain why the standard endorses this ambiguity: CREATE TABLE t1 (a VARCHAR, b VARCHAR) The length of `a` and `b` is left up to the implementers:
by starik36 4y ago
Can someone explain why the standard endorses this ambiguity:
CREATE TABLE t1 (a VARCHAR, b VARCHAR)
The length of `a` and `b` is left up to the implementers: "an implementation-defined default limit will be applied."
Why even allow ambiguity in the first place? This is just asking for problems.
- treeman79 4y agoPeople don’t interchange databases that often.
- osigurdson 4y agoSome people (unfortunately) have to support multiple database brands.
- masklinn 4y agoIn which case this‘ll hurt them no more than the current wide-spread incompatibilities between basic data types e.g. oracle not making a difference between NULL and an empty string, some databases defining storage limits in bytes where others use “characters” (whatever they mean by that), databases ignoring length limit versus truncating versus erroring (possibly the same database engine based on settings), …, and on top of that the database-specific limitations on indexing.
- paulryanrogers 4y agoLikely as a way to ask for arbitrary text up to something smaller than TEXT. The VARCHAR(000) form is already limited in its max by implementations.
- gaganyaan 4y agoI don't have any special knowledge, but I would speculate that it's for approximately the same reasons C allows you to define a byte as 7 bits: Backwards compatibility that let everyone agree on a standard
- mananaysiempre 4y agoAs 7, no (CHAR_BIT is required to be at least 8, see 5.2.4.2.1p1), but as 9, yes. Ancient machines aside, there are apparently DSPs with 16- or 32-bit machine bytes (addressable units), and people would prefer not to kludge 8-bit C bytes on top of that even if they could by fattening the pointers a bit. Of course, the question of how the hell you are going to reconcile pervasive 8-bit storage and the C standard’s requirement that fputc|fgetc roundtrip every possible byte is still open—see the current committee chair’s grump about that[1]. [1] https://thephd.dev/conformance-should-mean-something-fputc-and-freestanding https://thephd.dev/conformance-should-mean-something-fputc-a...
- paulddraper 4y agoIIRC SQL already allows default limits for `NUMERIC`, `DECIMAL`, `FLOAT`, and `TIMESTAMP`. This is simply allowing it for `VARCHAR` as well. In a sense, making it more consistent :)
- dspillett 4y agoA wonderful example of illogical logic – officially making things more consistently inconsistent!