[SQL] get attribute from XML
Hi, while parsing this type of XML: Q91G55 i tried this query to get the modified attribute select xpath('//entry/modified/text()',xml) from xml_sprot limit 10; but it doesn't work. So im asking if anyone can help me with that. Thanx in advance -- --- Viktor Bojović --- Wherever I go, Murphy goes with me
Re: [SQL] get attribute from XML
Dear Viktor, 'modified' is an attribute node, so you need to use the @ sign to acquire its value: mschatte=# select xpath( '//entry/@modified', '' ); xpath -- {2009-07-07} (1 row) HTH M.S. On Tue, Oct 12, 2010 at 1:03 AM, Viktor Bojović wrote: > Hi, > while parsing this type of XML: > > Q91G55 > > i tried this query to get the modified attribute > select xpath('//entry/modified/text()',xml) from xml_sprot limit 10; > but it doesn't work. > So im asking if anyone can help me with that. > Thanx in advance > -- > --- > Viktor Bojović > --- > Wherever I go, Murphy goes with me > -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
[SQL] Is there a conditional string-concatenation ?
Hi, Is there a conditional string-concatenation ? I'd like to have an elegant way to connect 2 strings with some 3rd element between only if there really are 2 strings to connect. e.g. MyCat ( 'John', '_', 'Doe' ) --> 'John_Doe' while MyCat ( 'John', '_', '' ) --> 'John' MyCat ( '', '_', 'Doe' ) --> 'Doe' MyCat ( '', '_', '' ) --> NULL It should treat NULL and '' equally as empty and it should trim each of the 3 elements. so MyCat ( ' John ', '_', NULL ) --> 'John' MyCat ( 'John', NULL, 'Doe' ) --> 'JohnDoe' -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql
Re: [SQL] Is there a conditional string-concatenation ?
On Tue, Oct 12, 2010 at 06:09:07AM +0200, Andreas wrote: > Hi, > Is there a conditional string-concatenation ? Perhaps this: CREATE OR REPLACE FUNCTION mycat(text, text, text) RETURNS TEXT LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN $1 IS NULL OR $1 = '' THEN trim($3) WHEN $3 IS NULL OR $3 = '' THEN trim($1) ELSE trim($1) || trim(coalesce($2, '')) || trim($3) END; -- Joshua Tolley / eggyknap End Point Corporation http://www.endpoint.com signature.asc Description: Digital signature
Re: [SQL] Is there a conditional string-concatenation ?
2010/10/12 Andreas : > Hi, > Is there a conditional string-concatenation ? > > I'd like to have an elegant way to connect 2 strings with some 3rd element > between only if there really are 2 strings to connect. > > e.g. > MyCat ( 'John', '_', 'Doe' ) --> 'John_Doe' > while > MyCat ( 'John', '_', '' ) --> 'John' > MyCat ( '', '_', 'Doe' ) --> 'Doe' > MyCat ( '', '_', '' ) --> NULL > > It should treat NULL and '' equally as empty > and it should trim each of the 3 elements. > > so > MyCat ( ' John ', '_', NULL ) --> 'John' > MyCat ( 'John', NULL, 'Doe' ) --> 'JohnDoe' > Try: bdteste=# SELECT nullif(ltrim(rtrim(coalesce(c1,'') || coalesce(c2,'') || coalesce(c3,''),' _'),' _'),'') bdteste-# FROM (VALUES ('John', '_', 'Doe'),('John', '_', ''),('', '_', 'Doe'),('', '_', ''),(' John ', '_', NULL),('John', NULL, 'Doe')) AS foo(c1,c2,c3); nullif -- John_Doe John Doe John JohnDoe (6 rows) Osvaldo -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql