@@ -307,14 +307,13 @@ JSValue pljs_datum_to_jsvalue(Datum arg, Oid argtype, JSContext *ctx) {
307
307
char * buf = palloc (VARSIZE_ANY_EXHDR (p ) + 1 );
308
308
memcpy (buf , VARDATA (p ), VARSIZE_ANY_EXHDR (p ));
309
309
310
- // buf[VARSIZE_ANY_EXHDR(p)] = '\0';
311
310
return_result = JS_NewStringLen (ctx , buf , VARSIZE_ANY_EXHDR (p ));
312
311
pfree (buf );
313
312
break ;
314
313
}
315
314
316
315
default :
317
- elog (NOTICE , "Unknown type: %d" , argtype );
316
+ elog (DEBUG3 , "Unknown type: %d" , argtype );
318
317
return_result = JS_NULL ;
319
318
}
320
319
@@ -519,18 +518,16 @@ Datum pljs_jsvalue_to_datum(JSValue val, Oid rettype, JSContext *ctx,
519
518
size_t plen ;
520
519
const char * str = JS_ToCStringLen (ctx , & plen , val );
521
520
522
- text * t = (text * )palloc (plen + VARHDRSZ );
523
- SET_VARSIZE (t , plen + VARHDRSZ );
524
- memcpy (VARDATA (t ), str , plen );
521
+ Datum ret = CStringGetTextDatum (str );
525
522
JS_FreeCString (ctx , str );
526
523
527
- PG_RETURN_TEXT_P ( t ) ;
524
+ return ret ;
528
525
break ;
529
526
}
530
527
531
528
case JSONOID : {
532
529
JSValueConst * argv = & val ;
533
- JSValue js = JS_JSONStringify (ctx , argv [0 ], argv [ 1 ], argv [ 2 ] );
530
+ JSValue js = JS_JSONStringify (ctx , argv [0 ], JS_UNDEFINED , JS_UNDEFINED );
534
531
size_t plen ;
535
532
const char * str = JS_ToCStringLen (ctx , & plen , js );
536
533
@@ -545,10 +542,9 @@ Datum pljs_jsvalue_to_datum(JSValue val, Oid rettype, JSContext *ctx,
545
542
546
543
case JSONBOID : {
547
544
JSValueConst * argv = & val ;
548
- JSValue js = JS_JSONStringify (ctx , argv [0 ], argv [ 1 ], argv [ 2 ] );
545
+ JSValue js = JS_JSONStringify (ctx , argv [0 ], JS_UNDEFINED , JS_UNDEFINED );
549
546
size_t plen ;
550
547
const char * str = JS_ToCStringLen (ctx , & plen , js );
551
-
552
548
// return it as a Datum, since there is no direct CStringGetJsonb exposed.
553
549
Datum ret = (Datum )DatumGetJsonbP (
554
550
DirectFunctionCall1 (jsonb_in , (Datum )(char * )str ));
@@ -653,11 +649,11 @@ Datum pljs_jsvalue_to_datum(JSValue val, Oid rettype, JSContext *ctx,
653
649
654
650
return PointerGetDatum (buffer );
655
651
} else {
656
- elog (NOTICE , "Unknown array type, tag: %lld" , val .tag );
652
+ elog (DEBUG3 , "Unknown array type, tag: %lld" , val .tag );
657
653
for (uint8_t i = 0 ; i < 255 ; i ++ ) {
658
654
void * res = JS_GetOpaque (val , i );
659
655
if (res != NULL ) {
660
- elog (NOTICE , "class_id: %d" , i );
656
+ elog (DEBUG3 , "class_id: %d" , i );
661
657
}
662
658
}
663
659
@@ -666,7 +662,7 @@ Datum pljs_jsvalue_to_datum(JSValue val, Oid rettype, JSContext *ctx,
666
662
}
667
663
668
664
default :
669
- elog (NOTICE , "Unknown type: %d" , rettype );
665
+ elog (DEBUG3 , "Unknown type: %d" , rettype );
670
666
if (fcinfo ) {
671
667
PG_RETURN_NULL ();
672
668
} else {
0 commit comments