Re: XMLELEMENT produce a lower case of element name

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: XMLELEMENT produce a lower case of element name
Дата
Msg-id 1386213597725-5781776.post@n5.nabble.com
обсуждение исходный текст
Список 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.



В списке pgsql-sql по дате отправления:

Предыдущее
От: David Johnston
Дата:
Сообщение: Re: Results list String to comma separated int
Следующее
От: Dev Kumkar
Дата:
Сообщение: Scheduled Events