@@ -881,6 +881,44 @@ test('field names and types are exposed', function(done){
881
881
} ) ;
882
882
} ) ;
883
883
884
+ // See https://github.com/Vizzuality/CartoDB-SQL-API/issues/100
885
+ test ( 'numeric fields are rendered as numbers in JSON' , function ( done ) {
886
+ assert . response ( app , {
887
+ url : '/api/v1/sql?' + querystring . stringify ( {
888
+ q : "WITH inp AS ( SELECT 1::int2 as a, 2::int4 as b, " +
889
+ "3::int8 as c, 4::float4 as d, " +
890
+ "5::float8 as e, 6::numeric as f" +
891
+ ") SELECT a,b,c,d,e,f," +
892
+ " ARRAY[a] AS _a, " +
893
+ " ARRAY[b] AS _b, " +
894
+ " ARRAY[c] AS _c, " +
895
+ " ARRAY[d] AS _d, " +
896
+ " ARRAY[e] AS _e, " +
897
+ " ARRAY[f] AS _f " +
898
+ "FROM inp"
899
+ } ) ,
900
+ headers : { host : 'vizzuality.cartodb.com' } ,
901
+ method : 'GET'
902
+ } , { } , function ( res ) {
903
+ assert . equal ( res . statusCode , 200 , res . body ) ;
904
+ var parsedBody = JSON . parse ( res . body ) ;
905
+ var row = parsedBody . rows [ 0 ] ;
906
+ assert . equal ( typeof ( row . a ) , 'number' ) ;
907
+ assert . equal ( typeof ( row . b ) , 'number' ) ;
908
+ assert . equal ( typeof ( row . c ) , 'number' ) ;
909
+ assert . equal ( typeof ( row . d ) , 'number' ) ;
910
+ assert . equal ( typeof ( row . e ) , 'number' ) ;
911
+ assert . equal ( typeof ( row . f ) , 'number' ) ;
912
+ assert . equal ( typeof ( row . _a [ 0 ] ) , 'number' ) ;
913
+ assert . equal ( typeof ( row . _b [ 0 ] ) , 'number' ) ;
914
+ assert . equal ( typeof ( row . _c [ 0 ] ) , 'number' ) ;
915
+ assert . equal ( typeof ( row . _d [ 0 ] ) , 'number' ) ;
916
+ assert . equal ( typeof ( row . _e [ 0 ] ) , 'number' ) ;
917
+ assert . equal ( typeof ( row . _f [ 0 ] ) , 'number' ) ;
918
+ done ( ) ;
919
+ } ) ;
920
+ } ) ;
921
+
884
922
// Timezone information is retained with JSON output
885
923
//
886
924
// NOTE: results of these tests rely on the TZ env variable
0 commit comments