File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 11/*
2- * $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.9 2009/03/15 22:05:17 tgl Exp $
2+ * $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.10 2009/04/02 17:57:05 teodor Exp $
33 */
44#include "postgres.h"
55
@@ -446,7 +446,8 @@ hstore_out(PG_FUNCTION_ARGS)
446446{
447447 HStore * in = PG_GETARG_HS (0 );
448448 int buflen ,
449- i ;
449+ i ,
450+ nnulls = 0 ;
450451 char * out ,
451452 * ptr ;
452453 char * base = STRPTR (in );
@@ -460,8 +461,15 @@ hstore_out(PG_FUNCTION_ARGS)
460461 PG_RETURN_CSTRING (out );
461462 }
462463
463- buflen = (4 /* " */ + 2 /* => */ + 2 /* , */ ) * in -> size +
464- 2 /* esc */ * (VARSIZE (in ) - CALCDATASIZE (in -> size , 0 ));
464+ for (i = 0 ; i < in -> size ; i ++ )
465+ if (entries [i ].valisnull )
466+ nnulls ++ ;
467+
468+ buflen = (4 /* " */ + 2 /* => */ ) * ( in -> size - nnulls ) +
469+ ( 2 /* " */ + 2 /* => */ + 4 /* NULL */ ) * nnulls +
470+ 2 /* , */ * ( in -> size - 1 ) +
471+ 2 /* esc */ * (VARSIZE (in ) - CALCDATASIZE (in -> size , 0 )) +
472+ 1 /* \0 */ ;
465473
466474 out = ptr = palloc (buflen );
467475 for (i = 0 ; i < in -> size ; i ++ )
You can’t perform that action at this time.
0 commit comments