Search Postgresql Archives

Empty arrays vs. NULLs, 9.1 & 8.3

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Hi.  I had this piece of SQL, which ran fine on my 9.1 installation:

CASE WHEN NOT allow_output_screen THEN array['O_SCREEN'] ELSE
array[]::varchar[] END
 || CASE WHEN NOT allow_output_spreadsheet THEN array['O_TEMPLATE']
ELSE array[]::varchar[] END,

However, this failed miserably on someone else's 8.3:

ERROR:  syntax error at or near "]"
LINE 1: ...w_output_screen THEN array['O_SCREEN'] ELSE array[]::varchar

The 9.1 documentation
states you can construct an empty array with my syntax (that's how I
got it originally), but there is no mention of empty arrays in the
corresponding 8.3 page.

In 8.3, I can SELECT NULL::varchar[], which seems to behave the same
in my query.  The two don't seem to be exactly the same.  I'm a little
confused, however, as to the finer points or conceptual differences
between them, and also what the differences might be between 8.3 and

Sticking within 9.1, I ran this:

=>CREATE TEMPORARY TABLE array_fun( f1 varchar[] );
=>INSERT INTO array_fun VALUES (array[]::varchar[]),(NULL::varchar[]);


=> SELECT array_dims(f1) AS dims, f1 IS NULL as is_null, f1 ||
array['Item 2']::varchar[] AS concats,f1 FROM array_fun;

 dims | is_null |  concats   | f1
      | f       | {"Item 2"} | {}
      | t       | {"Item 2"} |
(2 rows)

If anyone can shed some light on this, and also how to construct an
empty array in 8.3, it would be great.  Thanks!


p.s.,  On a side note, unless I've overlooked them before, the "this
page in other versions..." links in the doc pages seem to be new, and
are immensely helpful.  Especially because Google searches often
return results to the older versions.  Thanks a lot to whoever did

AGENCY Software
A data system that puts you in control
(253) 245-3801

Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:

[Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Programming PHP]     [Kernel Newbies]     [PHP Classes]     [Find Someone Nice]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

Add to Google Powered by Linux