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 1
1
/*
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 $
3
3
*/
4
4
#include "postgres.h"
5
5
@@ -446,7 +446,8 @@ hstore_out(PG_FUNCTION_ARGS)
446
446
{
447
447
HStore * in = PG_GETARG_HS (0 );
448
448
int buflen ,
449
- i ;
449
+ i ,
450
+ nnulls = 0 ;
450
451
char * out ,
451
452
* ptr ;
452
453
char * base = STRPTR (in );
@@ -460,8 +461,15 @@ hstore_out(PG_FUNCTION_ARGS)
460
461
PG_RETURN_CSTRING (out );
461
462
}
462
463
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 */ ;
465
473
466
474
out = ptr = palloc (buflen );
467
475
for (i = 0 ; i < in -> size ; i ++ )
You can’t perform that action at this time.
0 commit comments