pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Passing XML column in an array
3+ messages / 2 participants
[nested] [flat]

* Passing XML column in an array
@ 2022-02-10 17:14 Garfield Lewis <garfield.lewis@lzlabs.com>
  2022-02-10 17:53 ` Re: Passing XML column in an array Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: Garfield Lewis @ 2022-02-10 17:14 UTC (permalink / raw)
  To: pgsql-general

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


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Passing XML column in an array
  2022-02-10 17:14 Passing XML column in an array Garfield Lewis <garfield.lewis@lzlabs.com>
@ 2022-02-10 17:53 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-02-10 18:13   ` Re: [EXT] Re: Passing XML column in an array Garfield Lewis <garfield.lewis@lzlabs.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2022-02-10 17:53 UTC (permalink / raw)
  To: Garfield Lewis <garfield.lewis@lzlabs.com>; +Cc: pgsql-general

Garfield Lewis <garfield.lewis@lzlabs.com> writes:
> 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 ()

The most obvious theory is that there are some nulls in the XT.XMLT1C1
column.  Since your code isn't bothering to check pXmlDataNulls[ix],
it would hit a null-pointer dereference when accessing pXmlData[ix].

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [EXT] Re: Passing XML column in an array
  2022-02-10 17:14 Passing XML column in an array Garfield Lewis <garfield.lewis@lzlabs.com>
  2022-02-10 17:53 ` Re: Passing XML column in an array Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-02-10 18:13   ` Garfield Lewis <garfield.lewis@lzlabs.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Garfield Lewis @ 2022-02-10 18:13 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general


>    The most obvious theory is that there are some nulls in the XT.XMLT1C1
>    column.  Since your code isn't bothering to check pXmlDataNulls[ix],
>    it would hit a null-pointer dereference when accessing pXmlData[ix].
>
>    			regards, tom lane

Thx, Tom... my bad...

Regards,
Garfield



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-02-10 18:13 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-02-10 17:14 Passing XML column in an array Garfield Lewis <garfield.lewis@lzlabs.com>
2022-02-10 17:53 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-02-10 18:13   ` Garfield Lewis <garfield.lewis@lzlabs.com>

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