Re: ARRAY() returning NULL instead of ARRAY[] resp. {}

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Markus Bertheau <twanger(at)bluetwanger(dot)de>, pgsql-sql(at)postgresql(dot)org
Subject: Re: ARRAY() returning NULL instead of ARRAY[] resp. {}
Date: 2005-05-26 19:06:44
Message-ID: 42961E44.7040701@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches pgsql-sql

Tom Lane wrote:
> I think he's got a good point, actually. We document the ARRAY-with-
> parens-around-a-SELECT syntax as
>
> The resulting one-dimensional array will have an element for
> each row in the subquery result, with an element type matching
> that of the subquery's output column.
>
> To me, that implies that a subquery result of no rows generates a
> one-dimensional array of no elements, not a null array.

OK, looks like I'm outnumbered.

But as far as I know, we have never had a way to produce a
one-dimensional empty array. Empty arrays thus far have been dimensionless.

Assuming we really want an empty 1D array, I created the attached patch.
This works fine, but now leaves a few oddities to be dealt with, e.g.:

regression=# select array_dims(array(select 1 where false));
array_dims
------------
[1:0]
(1 row)

Any thoughts on how this should be handled for an empty 1D array?

> The point Markus is complaining about seems like it should
> be easily fixable.

Well, "easily" is a relative term. My Postgres hacking neurons have
gotten kind of rusty lately -- but then maybe that was your underlying
point ;-)

Joe

Attachment Content-Type Size
current.81.diff text/x-patch 7.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Manfred Koizar 2005-05-26 22:04:52 Re: WAL replay failure after file truncation(?)
Previous Message Tom Lane 2005-05-26 18:46:31 Re: Fix for timestamp rouding

Browse pgsql-patches by date

  From Date Subject
Next Message ¥9800ねっと 2005-05-26 19:50:38 L@VDVDIwV[YxDVDI
Previous Message Tom Lane 2005-05-26 18:46:31 Re: Fix for timestamp rouding

Browse pgsql-sql by date

  From Date Subject
Next Message fpltgqgkre 2005-05-26 19:14:50 БЮДЖЕТИРОВАНИЕ, НАЛОГОВОЕ ПЛАНИРОВАНИЕ И ОПТИМИЗАЦИЯ НАЛОГООБЛОЖЕНИЯ, АВТОТРАНСПОРТ И АВТОМОБИЛЬНЫЕ УСЛУГИ kharkov.ua
Previous Message noor 2005-05-26 18:21:05 [Fwd: unsubscribe]