Re: Postgres 9.2 - XML string functions ?

From: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Postgres 9.2 - XML string functions ?
Date: 2015-01-27 05:21:17
Message-ID: 1422336077879-5835589.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Khangelani Gama-2 wrote
> Hi
>
>
>
> Please help, I have been asked why XML string functions do this, which is
> why does the second statement below return no rows. No matter what is on
> the select statement, they can select as many columns as they want but the
> XML function breaks it as soon as it is added.
>
>
>
>
>
> 1) select
> aud_id,act_typ,right(act_typ::text,1),fpp_cde,obo_aud_id,obo_aud_id||sku_cde
> as "Key" from sku_tran join audit using (aud_id) join action_typ using
> (act_typ) join branch using (br_cde) join sku using (sku_cde) where
> obo_aud_id=5252005 and audit.fpp_cde between '201408' and '201412' and
> (right(act_typ::text,1) = '5') and act_typ between 76000 and 76999;
>
> aud_id | act_typ | right | fpp_cde | obo_aud_id | Key
>
> 2585912 | 76005 | 5 | 201408 | 5252005 | 525200510053486
>
> (1 row)
>
> 2) select
> aud_id,act_typ,right(act_typ::text,1),fpp_cde,obo_aud_id,(unnest(xpath('.//checksumBr/text()',
> aud_xml::xml)))::text||obo_aud_id||sku_cde as "Key" from sku_tran join
> audit using (aud_id) join action_typ using (act_typ) join branch using
> (br_cde) join sku using (sku_cde) where obo_aud_id=5252005 and
> audit.fpp_cde between '201408' and '201412' and (right(act_typ::text,1) =
> '5') and act_typ between 76000 and 76999;
>
> aud_id | act_typ | right | fpp_cde | obo_aud_id | Key
>
> (0 rows)

When you unnest an empty array it returns an empty set. An empty set in the
select list causes the row it is sourced from to be excluded from the
output.

You can use a correlated subselect to instead have the result instead be
shown as NULL.

David J.

--
View this message in context: http://postgresql.nabble.com/Postgres-9-2-XML-string-functions-tp5835578p5835589.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Khangelani Gama 2015-01-27 05:25:19 Re: Postgres 9.2 - XML string functions ?
Previous Message Khangelani Gama 2015-01-27 04:25:52 Postgres 9.2 - XML string functions ?