Postgresql XML field type

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Postgresql XML field type

Postby Roberto Blasco » Wed Mar 01, 2017 10:31 pm

Hi all.

I am trying to insert a record in a postgresql table with a xml field.

Code: Select all
/** @type {JSFoundSet<db:/my_server/my_table>} */
var fs = databaseManager.getFoundSet("db:/my_server/my_table");
fs.newRecord();
fs.xml_data = '<xml><item>item1</item></xml>';
var bok = databaseManager.saveData(fs);


I have tried like an xml object as well ...

Code: Select all
/** @type {JSFoundSet<db:/my_server/my_table>} */
var fs = databaseManager.getFoundSet("db:/my_server/my_table");
fs.newRecord();
fs.xml_data = <xml><item>item1</item></xml>;
var bok = databaseManager.saveData(fs);


But it doesn't works .... any ideas?

Best regards. Roberto Blasco.

Servoy v.8.1.2 - build 3031
Postgresql (the bundle with servoy)
Un saludo. Roberto.

Madrid - Spain
Tfno: (+34) 625653066
E-mail: roberto.blasco.serrano@gmail.com
User avatar
Roberto Blasco
007
 
Posts: 355
Joined: Tue Apr 08, 2008 7:18 pm
Location: Madrid / Spain

Re: Postgresql XML field type

Postby Bernd.N » Thu Mar 02, 2017 9:01 am

Hi Roberto,
here are some thoughts:
the postgres doc https://www.postgresql.org/docs/9.6/static/datatype-xml.html says for XML types "... Its advantage over storing XML data in a text field is that it checks the input values for well-formedness, and there are support functions to perform type-safe operations on it..."
Maybe that check is not working and postgres rejects inserting that XML, without telling you?
So I would first check what happens if you do a normal SQL INSERT with your desired XML-string.
Then I would also add a normal string field and check if this works:
Code: Select all
fs.string_field = '<xml><item>item1</item></xml>';

We always use a record var when adding a record, that might be more save.
Code: Select all
var record = foundset.getRecord(foundset.newRecord())
record.xml_data = ....

When you go to pgAdmin and have a look to your sample table, what does the CREATE TABLE command show regarding your field?
Are you sure Servoy supports postgres-XML-fields at all?
What is the type Servoy shows in its table editor for that XML-field? I would guess it is TEXT?
Bernd Korthaus
LinkedIn
Servoy 7.4.9 SC postgreSQL 9.4.11 Windows 10 Pro
User avatar
Bernd.N
 
Posts: 544
Joined: Mon Oct 21, 2013 5:57 pm
Location: Langenhorn, North Friesland, Germany


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests