pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Garfield Lewis <garfield.lewis@lzlabs.com>
To: PostgreSQL mailing lists <pgsql-general@postgresql.org>
Subject: Passing XML column in an array
Date: Thu, 10 Feb 2022 17:14:09 +0000
Message-ID: <247353C7-F577-46D7-9EB6-FA4CB8452D5F@lzlabs.com> (raw)

Hi All,

I have the following code:


141     if ( 0 != iXmlArrDim ) {

142         Datum    *pXmlData      = NULL;

143         bool     *pXmlDataNulls = NULL;

144         uint32_t  iXmlCount     = 0;

145         bool      bFirstTime    = true;

146

147         Assert( XMLOID == ARR_ELEMENTS( pXmlDataArr ) );

148

149         deconstruct_array( pXmlDataArr,

150                            XMLOID,

151                            -1,

152                            false,

153                            'i',

154                            &pXmlData,

155                            &pXmlDataNulls,

156                            (int32_t*)&iXmlCount );

157

158         initStringInfo( &xmlStr );

159

160         for ( size_t ix = 0; ix < iXmlCount; ++ix ) {

161             xmltype  *pX    = DatumGetXmlP( pXmlData[ix] );

162             char     *pData = VARDATA( pX );

163             uint32_t  iData = VARSIZE( pX ) - VARHDRSZ;

164

165             if ( !bFirstTime )

166                 appendStringInfoString( &xmlStr, ", " );

167             else

168                 bFirstTime = false;

169

170             appendStringInfoString( &xmlStr,

171                                     (const char*)lzXmlCharStrndup( pData,

172                                                                    iData ) );

173         }

174

175         pfree( pXmlData );

176         pfree( pXmlDataNulls );

177     }

I am trying to pass an array into a new function I am creating called lzxmlexists via the following statement:

wdbs=# SELECT "XT"."ROWKEY" , "XT"."XMLT1C1" FROM "LZQAAS"."T642_XML_T1" "XT" WHERE "ROWKEY"=64201 AND lzxmlexists( ' $XTX//DeptName[ . = $Dn    ]', 'DEFAULT', ARRAY["XT"."XMLT1C1"] ) ORDER BY "ROWKEY";

The column XT.XMLT1C1 exists because I can do a simple select to see the contents. The problem is that in the code above I hit the following error at line 161.

160             for ( size_t ix = 0; ix < iXmlCount; ++ix ) {
(gdb)
163                 xmltype  *pX    =  DatumGetXmlP( pXmlData[ix] );
(gdb)

Program received signal SIGSEGV, Segmentation fault.
0x00000000008b3514 in pg_detoast_datum ()

Obviously, I’ve done something wrong, or I am misunderstanding something.

BTW, if I change the array input to something like this ARRAY[‘something-variable’::xml] it works no problem, but it seems as though getting the input from the column results in garbage that traps.

Any suggestion/help would be greatly appreciated.

Regards,
Garfield


view thread (3+ messages)  latest in thread

Message-ID: <247353C7-F577-46D7-9EB6-FA4CB8452D5F@lzlabs.com>
Permalink:  ../247353C7-F577-46D7-9EB6-FA4CB8452D5F@lzlabs.com/
Also on:    postgresql.org/message-id/247353C7-F577-46D7-9EB6-FA4CB8452D5F@lzlabs.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: garfield.lewis@lzlabs.com
  Subject: Re: Passing XML column in an array
  In-Reply-To: <247353C7-F577-46D7-9EB6-FA4CB8452D5F@lzlabs.com>
  References: <247353C7-F577-46D7-9EB6-FA4CB8452D5F@lzlabs.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox