mirror of
				https://github.com/postgres/postgres.git
				synced 2025-10-31 00:03:57 -04:00 
			
		
		
		
	Allow empty string object keys in json_object().
This makes the behaviour consistent with the json parser, other json-generating functions, and the JSON standards.
This commit is contained in:
		
							parent
							
								
									d7cdf6ee36
								
							
						
					
					
						commit
						4ebe3519e1
					
				| @ -2184,10 +2184,6 @@ json_object(PG_FUNCTION_ARGS) | |||||||
| 					 errmsg("null value not allowed for object key"))); | 					 errmsg("null value not allowed for object key"))); | ||||||
| 
 | 
 | ||||||
| 		v = TextDatumGetCString(in_datums[i * 2]); | 		v = TextDatumGetCString(in_datums[i * 2]); | ||||||
| 		if (v[0] == '\0') |  | ||||||
| 			ereport(ERROR, |  | ||||||
| 					(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |  | ||||||
| 					 errmsg("empty value not allowed for object key"))); |  | ||||||
| 		if (i > 0) | 		if (i > 0) | ||||||
| 			appendStringInfoString(&result, ", "); | 			appendStringInfoString(&result, ", "); | ||||||
| 		escape_json(&result, v); | 		escape_json(&result, v); | ||||||
| @ -2272,10 +2268,6 @@ json_object_two_arg(PG_FUNCTION_ARGS) | |||||||
| 					 errmsg("null value not allowed for object key"))); | 					 errmsg("null value not allowed for object key"))); | ||||||
| 
 | 
 | ||||||
| 		v = TextDatumGetCString(key_datums[i]); | 		v = TextDatumGetCString(key_datums[i]); | ||||||
| 		if (v[0] == '\0') |  | ||||||
| 			ereport(ERROR, |  | ||||||
| 					(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), |  | ||||||
| 					 errmsg("empty value not allowed for object key"))); |  | ||||||
| 		if (i > 0) | 		if (i > 0) | ||||||
| 			appendStringInfoString(&result, ", "); | 			appendStringInfoString(&result, ", "); | ||||||
| 		escape_json(&result, v); | 		escape_json(&result, v); | ||||||
|  | |||||||
| @ -1213,9 +1213,13 @@ ERROR:  mismatched array dimensions | |||||||
| -- null key error | -- null key error | ||||||
| select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}'); | select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}'); | ||||||
| ERROR:  null value not allowed for object key | ERROR:  null value not allowed for object key | ||||||
| -- empty key error | -- empty key is allowed | ||||||
| select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}'); | select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}'); | ||||||
| ERROR:  empty value not allowed for object key |                      json_object                      | ||||||
|  | ----------------------------------------------------- | ||||||
|  |  {"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"} | ||||||
|  | (1 row) | ||||||
|  | 
 | ||||||
| -- json_to_record and json_to_recordset | -- json_to_record and json_to_recordset | ||||||
| select * from json_to_record('{"a":1,"b":"foo","c":"bar"}') | select * from json_to_record('{"a":1,"b":"foo","c":"bar"}') | ||||||
|     as x(a int, b text, d text); |     as x(a int, b text, d text); | ||||||
|  | |||||||
| @ -1209,9 +1209,13 @@ ERROR:  mismatched array dimensions | |||||||
| -- null key error | -- null key error | ||||||
| select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}'); | select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}'); | ||||||
| ERROR:  null value not allowed for object key | ERROR:  null value not allowed for object key | ||||||
| -- empty key error | -- empty key is allowed | ||||||
| select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}'); | select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}'); | ||||||
| ERROR:  empty value not allowed for object key |                      json_object                      | ||||||
|  | ----------------------------------------------------- | ||||||
|  |  {"a" : "1", "b" : "2", "" : "3", "d e f" : "a b c"} | ||||||
|  | (1 row) | ||||||
|  | 
 | ||||||
| -- json_to_record and json_to_recordset | -- json_to_record and json_to_recordset | ||||||
| select * from json_to_record('{"a":1,"b":"foo","c":"bar"}') | select * from json_to_record('{"a":1,"b":"foo","c":"bar"}') | ||||||
|     as x(a int, b text, d text); |     as x(a int, b text, d text); | ||||||
|  | |||||||
| @ -435,7 +435,7 @@ select json_object('{a,b,c,"d e f"}','{1,2,3,"a b c",g}'); | |||||||
| 
 | 
 | ||||||
| select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}'); | select json_object('{a,b,NULL,"d e f"}','{1,2,3,"a b c"}'); | ||||||
| 
 | 
 | ||||||
| -- empty key error | -- empty key is allowed | ||||||
| 
 | 
 | ||||||
| select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}'); | select json_object('{a,b,"","d e f"}','{1,2,3,"a b c"}'); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user