Tuesday, 16 August 2016

PostrgreSQL : Export - Import Data

Status : Draft

query_to_xml(query text, nulls boolean, tableforest boolean, targetns text)


SELECT * FROM query_to_xml('select * from set_soal where id_set_soal=64',true,false,'') xml;

"<table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<row>
  <id_set_soal>64</id_set_soal>
  <nama>0 Aquaponik Dasar</nama>
  <tahun>2016</tahun>
  <ujian>aquaponik</ujian>
</row>

</table>
"

Jika menggunakan prepared statement, SQL nya harus ditulis seperti ini :

SELECT * FROM query_to_xml('SELECT * FROM set_soal WHERE id_set_soal = '|| $1,true,false,'') set_xml;


Referensi

  1. Mapping Tables to XML, https://www.postgresql.org/docs/current/static/functions-xml.html#FUNCTIONS-XML-MAPPING
  2. Using query_to_xml in PostgreSQL with prepared statements, http://stackoverflow.com/questions/14897398/using-query-to-xml-in-postgresql-with-prepared-statements

No comments:

Post a Comment