Re: Postgresql : effecteur des update avec un champ XML ?

Lists: pgsql-fr-generale
From: celati Laurent <laurent(dot)celati(at)gmail(dot)com>
To: pgsql-fr-generale <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Postgresql : effecteur des update avec un champ XML ?
Date: 2024-12-16 16:33:14
Message-ID: CAHByMH2sRSio8UtX6LhWP9u16zToyQd4EetH=7S013bEtRa1Aw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-fr-generale

Bonjour,

Je travaille avec postgreSQL. J'ai une table avec plusieurs colonnes. L'une
d'elles (la colonne 'data') est une donnée de type XML. Savez-vous si il y
aurait un moyen de faire des mises à jour/update sur cette colonne XML ?
Pour exemple, je colle une requête qui fonctionne permettant d'extraire
certains éléments de cette colonne XML.

select id, unnest(xpath(
'//cit:CI_Organisation/cit:name/gco:CharacterString/text()',
CAST(data AS XML),
ARRAY[
ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0'],
ARRAY['mdb','http://standards.iso.org/iso/19115/-3/mdb/2.0'],
ARRAY['cat','http://standards.iso.org/iso/19115/-3/cat/1.0'],
])) as orga_name, changedate, createdate, displayorder,
doctype, extra, popularity, rating, root, schemaid, title, istemplate,
isharvested, harvesturi,
harvestuuid, groupowner, metadata.owner, metadata.source,
uuidfrom public.metadata

Existerai-t-il un moyen d’effectuer une mise à jour/update sur ce champ
XML ?

Un grand merci.


From: emmanuel(dot)remy94(at)icloud(dot)com
To: celati Laurent <laurent(dot)celati(at)gmail(dot)com>
Cc: pgsql-fr-generale <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: Postgresql : effecteur des update avec un champ XML ?
Date: 2024-12-17 08:03:22
Message-ID: A44B1925-BD1D-463F-B6C7-AA2887925AC6@icloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-fr-generale

Hello,

Je crois bien que cela nécessite de travailler sur du texte qui sera ensuite re-parsé en XML.

Quelque chose comme:

UPDATE public.metadata
SET data = xmlparse(DOCUMENT
REPLACE(
xmlserialize(CONTENT data AS TEXT),
'<gco:CharacterString>Ancienne Valeur</gco:CharacterString>',
'<gco:CharacterString>Nouvelle Valeur</gco:CharacterString>'
)
)
WHERE id = 1;

Bonne continuation,

Emmanuel
CASDEN

>
> Le 16 déc. 2024 à 22:18, celati Laurent <laurent(dot)celati(at)gmail(dot)com> a écrit :
> 
>
> Bonjour,
>
> Je travaille avec postgreSQL. J'ai une table avec plusieurs colonnes. L'une d'elles (la colonne 'data') est une donnée de type XML. Savez-vous si il y aurait un moyen de faire des mises à jour/update sur cette colonne XML ? Pour exemple, je colle une requête qui fonctionne permettant d'extraire certains éléments de cette colonne XML.
>
> select id, unnest(xpath(
> '//cit:CI_Organisation/cit:name/gco:CharacterString/text()',
> CAST(data AS XML),
> ARRAY[
> ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
> ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0'],
> ARRAY['mdb','http://standards.iso.org/iso/19115/-3/mdb/2.0'],
> ARRAY['cat','http://standards.iso.org/iso/19115/-3/cat/1.0'],
> ])) as orga_name, changedate, createdate, displayorder, doctype, extra, popularity, rating, root, schemaid, title, istemplate, isharvested, harvesturi,
> harvestuuid, groupowner, metadata.owner, metadata.source, uuid
> from public.metadata
> Existerai-t-il un moyen d’effectuer une mise à jour/update sur ce champ XML ?
> Un grand merci.


From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: celati Laurent <laurent(dot)celati(at)gmail(dot)com>
Cc: pgsql-fr-generale <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: Postgresql : effecteur des update avec un champ XML ?
Date: 2024-12-17 08:38:31
Message-ID: CAECtzeWHLO35ASXkWksirDYof=6BWDmWi7Y3orgSUMEsvWaxkA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-fr-generale

Bonjour,

Le lun. 16 déc. 2024 à 22:18, celati Laurent <laurent(dot)celati(at)gmail(dot)com> a
écrit :

>
> Bonjour,
>
> Je travaille avec postgreSQL. J'ai une table avec plusieurs colonnes.
> L'une d'elles (la colonne 'data') est une donnée de type XML. Savez-vous si
> il y aurait un moyen de faire des mises à jour/update sur cette colonne XML
> ? Pour exemple, je colle une requête qui fonctionne permettant d'extraire
> certains éléments de cette colonne XML.
>
> select id, unnest(xpath(
> '//cit:CI_Organisation/cit:name/gco:CharacterString/text()',
> CAST(data AS XML),
> ARRAY[
> ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
> ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0'],
> ARRAY['mdb','http://standards.iso.org/iso/19115/-3/mdb/2.0'],
> ARRAY['cat','http://standards.iso.org/iso/19115/-3/cat/1.0'],
> ])) as orga_name, changedate, createdate, displayorder, doctype, extra, popularity, rating, root, schemaid, title, istemplate, isharvested, harvesturi,
> harvestuuid, groupowner, metadata.owner, metadata.source, uuidfrom public.metadata
>
> Existerai-t-il un moyen d’effectuer une mise à jour/update sur ce champ
> XML ?
>
> Un grand merci.
>

À ma connaissance, le seul moyen est de mettre à jour la colonne complète.

--
Guillaume.


From: celati Laurent <laurent(dot)celati(at)gmail(dot)com>
To: emmanuel(dot)remy94(at)icloud(dot)com
Cc: pgsql-fr-generale <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: Postgresql : effecteur des update avec un champ XML ?
Date: 2024-12-17 16:44:20
Message-ID: CAHByMH20iSr_SoYv0U6MyVKxSxf99Z4iEOTW9uWaC=9bzL=7sg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-fr-generale

Bonjour,
Merci pour votre proposition. Je viens de la tester. Lorsque je tente :
UPDATE public.metadata
SET data = xmlparse(DOCUMENT
REPLACE(
xmlserialize(CONTENT data AS TEXT),
'<gco:CharacterString>WIPSEA</gco:CharacterString>',
'<gco:CharacterString>WIPSEA</gco:CharacterString>'
)
)
WHERE id = 1;

Voici c que j'obtiens :

ERROR: argument of XMLSERIALIZE must be type xml, not type text LINE 4:
xmlserialize(CONTENT data AS TEXT), ^ SQL state: 42804 Character: 96

Pour votre information, ma colonne 'data' de la table metadata qui contient
le contenu en XML
est de type text : [image: image.png]

Le mar. 17 déc. 2024 à 09:03, <emmanuel(dot)remy94(at)icloud(dot)com> a écrit :

> Hello,
>
> Je crois bien que cela nécessite de travailler sur du texte qui sera
> ensuite re-parsé en XML.
>
> Quelque chose comme:
>
> UPDATE public.metadata
> SET data = xmlparse(DOCUMENT
> REPLACE(
> xmlserialize(CONTENT data AS TEXT),
> '<gco:CharacterString>Ancienne Valeur</gco:CharacterString>',
> '<gco:CharacterString>Nouvelle Valeur</gco:CharacterString>'
> )
> )
> WHERE id = 1;
>
> Bonne continuation,
>
> Emmanuel
> CASDEN
>
>
>
> Le 16 déc. 2024 à 22:18, celati Laurent <laurent(dot)celati(at)gmail(dot)com> a
> écrit :
>
> 
>
> Bonjour,
>
> Je travaille avec postgreSQL. J'ai une table avec plusieurs colonnes.
> L'une d'elles (la colonne 'data') est une donnée de type XML. Savez-vous si
> il y aurait un moyen de faire des mises à jour/update sur cette colonne XML
> ? Pour exemple, je colle une requête qui fonctionne permettant d'extraire
> certains éléments de cette colonne XML.
>
> select id, unnest(xpath(
> '//cit:CI_Organisation/cit:name/gco:CharacterString/text()',
> CAST(data AS XML),
> ARRAY[
> ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
> ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0'],
> ARRAY['mdb','http://standards.iso.org/iso/19115/-3/mdb/2.0'],
> ARRAY['cat','http://standards.iso.org/iso/19115/-3/cat/1.0'],
> ])) as orga_name, changedate, createdate, displayorder, doctype, extra, popularity, rating, root, schemaid, title, istemplate, isharvested, harvesturi,
> harvestuuid, groupowner, metadata.owner, metadata.source, uuidfrom public.metadata
>
> Existerai-t-il un moyen d’effectuer une mise à jour/update sur ce champ
> XML ?
>
> Un grand merci.
>
>


From: Yves Jacolin <yves(dot)jacolin(at)camptocamp(dot)com>
To: celati Laurent <laurent(dot)celati(at)gmail(dot)com>
Cc: emmanuel(dot)remy94(at)icloud(dot)com, pgsql-fr-generale <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: Postgresql : effecteur des update avec un champ XML ?
Date: 2024-12-19 08:11:28
Message-ID: CAO8EQxbVrySOoRXKQJ5i6g1e45zQu5iQJzABxcEju1pzMb+6-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-fr-generale

Bonjour Laurent,

D'où vient ce champ ? De GeoNetwork ? Ne peux tu pas caster le champ texte ?

Y.

Le mer. 18 déc. 2024 à 00:18, celati Laurent <laurent(dot)celati(at)gmail(dot)com> a
écrit :

> Bonjour,
> Merci pour votre proposition. Je viens de la tester. Lorsque je tente :
> UPDATE public.metadata
> SET data = xmlparse(DOCUMENT
> REPLACE(
> xmlserialize(CONTENT data AS TEXT),
> '<gco:CharacterString>WIPSEA</gco:CharacterString>',
> '<gco:CharacterString>WIPSEA</gco:CharacterString>'
> )
> )
> WHERE id = 1;
>
> Voici c que j'obtiens :
>
> ERROR: argument of XMLSERIALIZE must be type xml, not type text LINE 4:
> xmlserialize(CONTENT data AS TEXT), ^ SQL state: 42804 Character: 96
>
>
> Pour votre information, ma colonne 'data' de la table metadata qui
> contient le contenu en XML
> est de type text : [image: image.png]
>
>
>
>
> Le mar. 17 déc. 2024 à 09:03, <emmanuel(dot)remy94(at)icloud(dot)com> a écrit :
>
>> Hello,
>>
>> Je crois bien que cela nécessite de travailler sur du texte qui sera
>> ensuite re-parsé en XML.
>>
>> Quelque chose comme:
>>
>> UPDATE public.metadata
>> SET data = xmlparse(DOCUMENT
>> REPLACE(
>> xmlserialize(CONTENT data AS TEXT),
>> '<gco:CharacterString>Ancienne Valeur</gco:CharacterString>',
>> '<gco:CharacterString>Nouvelle Valeur</gco:CharacterString>'
>> )
>> )
>> WHERE id = 1;
>>
>> Bonne continuation,
>>
>> Emmanuel
>> CASDEN
>>
>>
>>
>> Le 16 déc. 2024 à 22:18, celati Laurent <laurent(dot)celati(at)gmail(dot)com> a
>> écrit :
>>
>> 
>>
>> Bonjour,
>>
>> Je travaille avec postgreSQL. J'ai une table avec plusieurs colonnes.
>> L'une d'elles (la colonne 'data') est une donnée de type XML. Savez-vous si
>> il y aurait un moyen de faire des mises à jour/update sur cette colonne XML
>> ? Pour exemple, je colle une requête qui fonctionne permettant d'extraire
>> certains éléments de cette colonne XML.
>>
>> select id, unnest(xpath(
>> '//cit:CI_Organisation/cit:name/gco:CharacterString/text()',
>> CAST(data AS XML),
>> ARRAY[
>> ARRAY['cit', 'http://standards.iso.org/iso/19115/-3/cit/2.0'],
>> ARRAY['gco', 'http://standards.iso.org/iso/19115/-3/gco/1.0'],
>> ARRAY['mdb','http://standards.iso.org/iso/19115/-3/mdb/2.0'],
>> ARRAY['cat','http://standards.iso.org/iso/19115/-3/cat/1.0'],
>> ])) as orga_name, changedate, createdate, displayorder, doctype, extra, popularity, rating, root, schemaid, title, istemplate, isharvested, harvesturi,
>> harvestuuid, groupowner, metadata.owner, metadata.source, uuidfrom public.metadata
>>
>> Existerai-t-il un moyen d’effectuer une mise à jour/update sur ce champ
>> XML ?
>>
>> Un grand merci.
>>
>>

--
[image: This is Yves Jacolin's card. Their email is
yves(dot)jacolin(at)camptocamp(dot)com(dot) Their phone number is +33 6 18 75 42 21. Their
phone number is +33 4 58 48 20 43. Their phone number is +41 21 619 10 43.]
<https://hihello.me/p/c7a536d1-5177-4817-8924-ebb067e58d4f>