Re: XMLELEMENT produce a lower case of element name

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: XMLELEMENT produce a lower case of element name
Date: 2013-12-05 03:19:57
Message-ID: 1386213597725-5781776.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Andrey wrote
> Hi,
>
> I have got a query like
*
> SELECT xmlelement(name FOO);
*
>
> </br>
> </br>
> When I try it select the result is
> </br>
> </br>
*
> xmlelement
> </br>
> ------------
> </br>

>
*
>
> </br>
> </br>
> How can I save upper case in the element name?
> </br>
> </br>
> SHOW Server_version 9.3.0

*First: *

"Name"s in PostgreSQL are auto-lowercased when not enclosed in quotes:

SELECT 'one' AS ONE
and
SELECT 'one' AS oNe
and
SELECT 'one' AS one

all result in an output column with the name "one" (w/o quotes)

To force case-preservation you enclose the name in double-quotes (though the
stored name does not retain those quotes)

SELECT 'one' AS "ONE" --> ONE
SELECT 'one' AS "oNe" --> oNe

*Second:*

Type-casting forms (note there are other ways but they will not work in this
situation)

SELECT date '2013-10-01' AS actual_date

The above casts the literal <2013-10-01> to a date datatype.

SELECT xmlelement(name FOO)

The above casts the literal <FOO> to a "name" datatype - with a value of
"foo" (w/o quotes)

The explicit casting to name has the same behavior as all other names in
PostgreSQL; specifically that it auto-lowercases the value if not enclosed
in double-quotes.

*Thus:*

SELECT xmlelement(name "FOO")

gives you an element with case preserved (and w/o quotes, as noted/shown
above)

/Aside>/ To be honest I'm somewhat surprised by this behavior as this is the
only time I've encountered explicit "name" types and the casting of such in
this way. This is indeed how this specific function works, and it is well
documented - if you understand "names" and type-casting forms - but you are
unlikely to encounter this type of syntax as you explore other areas of
PostgreSQL.

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/XMLELEMENT-produce-a-lower-case-of-element-name-tp5780918p5781776.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

Browse pgsql-sql by date

  From Date Subject
Next Message Dev Kumkar 2013-12-11 11:38:12 Scheduled Events
Previous Message David Johnston 2013-12-05 03:02:07 Re: Results list String to comma separated int