Re: Should array_length() Return NULL
От | Tom Lane |
---|---|
Тема | Re: Should array_length() Return NULL |
Дата | |
Msg-id | 25958.1363462073@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: Should array_length() Return NULL (Brendan Jurd <direvus@gmail.com>) |
Ответы |
Re: Should array_length() Return NULL
|
Список | pgsql-hackers |
Brendan Jurd <direvus@gmail.com> writes: > On 17 March 2013 05:19, Tom Lane <tgl@sss.pgh.pa.us> wrote: >> Perhaps not. I think for most uses, a 1-D zero-length array would be >> just as good. I guess what I'd want to know is whether we also need >> to support higher-dimensional zero-size arrays, and if so, what does >> the I/O syntax for those look like? > If I'm reading right, in our current implementation of array > dimensionality, there can be no such thing as a higher-dimensional > zero-length array anyhow. Postgres doesn't care about how many > dimensions you define for an array, it uses the "quacks like a duck" > test for number of dimensions. For example: > postgres=# SELECT ARRAY[1]::int[][], array_dims(ARRAY[1]::int[][]); > array | array_dims > -------+------------ > {1} | [1:1] Um, this seems to be conflating the issue with a different one, which is that the type system doesn't care how many dimensions arrays have. So "int[]" and "int[][]" are the same type. That's slightly annoying but I'm not sure it's really worth changing. What I'm concerned about here is whether these expressions shouldn't be yielding different data values: regression=# select array[]::int[];array -------{} (1 row) regression=# select array[array[]]::int[];array -------{} (1 row) regression=# select array[array[],array[]]::int[];array -------{} (1 row) Right now, if we did make them produce what they appear to mean, the array I/O functions would have a problem with representing the results: regression=# select '{}'::int[];int4 ------{} (1 row) regression=# select '{{}}'::int[]; ERROR: malformed array literal: "{{}}" LINE 1: select '{{}}'::int[]; ^ regression=# select '{{},{}}'::int[]; ERROR: malformed array literal: "{{},{}}" LINE 1: select '{{},{}}'::int[]; ^ So I think we'd need to fix that before we could go very far in this direction. regards, tom lane
В списке pgsql-hackers по дате отправления: