Re: typmod is always -1
От | Chapman Flack |
---|---|
Тема | Re: typmod is always -1 |
Дата | |
Msg-id | 56EB4B6B.5020405@anastigmatix.net обсуждение исходный текст |
Ответ на | Re: typmod is always -1 (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: typmod is always -1
|
Список | pgsql-hackers |
On 03/17/16 09:35, Tom Lane wrote: > Chapman Flack <chap@anastigmatix.net> writes: >> I'm in the same boat ... I have an input function I want to test, and so >> far I have failed to think of *any* sql construct that causes it to be >> invoked with other than -1 for the typmod. > > COPY was the first case a quick grep came across. Thanks, that does make a working test. Given a table with a typmod'd column, COPY FROM exercises the 'input' function with a typmod != -1, and COPY FROM (FORMAT BINARY) likewise exercises the 'receive' function. While I'm here, I guess I should check the sense I am getting of what can and can't be workable semantics for type modifiers. It seems that a typmod can only be used restrict the set of possible values of the unmodified type (as clearly seen in the language "length conversion cast", since certainly a typmod allowing { string | length < N } is doing nothing but enforcing a subset of { string }. Each element of the subset is still a valid element of the whole set (naturally, boring) *and has to be represented the same way* (interesting): the representation mustn't do clever things that you would need to know the typmod in order to interpret, because most uses of a value are without access to the typmod. So, the generalization of "length conversion cast" could be something like "typmod application cast" and the only things a typmod application cast can do to a value V are: 1. pass V unchanged if it is in the subset implied by the typmod 2. silently pass some V' that is in that subset and "close to" V in some sense (longest initial substring shorter than N,nearest numeric value with no more than N precision digits, etc.) 3. fail with sometimes the choice of (2) or (3) depending on whether the cast is explicit or not. All in all, very like a domain, except a domain can only do (1) or (3), not (2). Differences in representation, like short strings getting 1-byte headers, are only possible as a consequence of a lower layer doing that consistently to all values that happen to be short, and not as an effect of a typmod. Am I getting it about right? -Chap
В списке pgsql-hackers по дате отправления: