Skip to content

Latest commit

 

History

History
112 lines (76 loc) · 5.41 KB

20240126_02.md

File metadata and controls

112 lines (76 loc) · 5.41 KB

PostgreSQL 17 preview - Implement various jsonpath methods

作者

digoal

日期

2024-01-26

标签

PostgreSQL , PolarDB , DuckDB , jsonpath , SQL feature


背景

https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=66ea94e8e606529bb334515f388c62314956739e

Implement various jsonpath methods  
  
author	Andrew Dunstan <andrew@dunslane.net>	  
Thu, 25 Jan 2024 15:15:43 +0000 (10:15 -0500)  
committer	Andrew Dunstan <andrew@dunslane.net>	  
Thu, 25 Jan 2024 15:15:43 +0000 (10:15 -0500)  
commit	66ea94e8e606529bb334515f388c62314956739e  
tree	82bbcc7b7837412ca86df6b3a04e7046f51871e5	tree  
parent	924d046dcf55887c98a1628675a30f4b0eebe556	commit | diff  
Implement various jsonpath methods  
  
This commit implements ithe jsonpath .bigint(), .boolean(),  
.date(), .decimal([precision [, scale]]), .integer(), .number(),  
.string(), .time(), .time_tz(), .timestamp(), and .timestamp_tz()  
methods.  
  
.bigint() converts the given JSON string or a numeric value to  
the bigint type representation.  
  
.boolean() converts the given JSON string, numeric, or boolean  
value to the boolean type representation.  In the numeric case, only  
integers are allowed. We use the parse_bool() backend function  
to convert a string to a bool.  
  
.decimal([precision [, scale]]) converts the given JSON string  
or a numeric value to the numeric type representation.  If precision  
and scale are provided for .decimal(), then it is converted to the  
equivalent numeric typmod and applied to the numeric number.  
  
.integer() and .number() convert the given JSON string or a  
numeric value to the int4 and numeric type representation.  
  
.string() uses the datatype's output function to convert numeric  
and various date/time types to the string representation.  
  
The JSON string representing a valid date/time is converted to the  
specific date or time type representation using jsonpath .date(),  
.time(), .time_tz(), .timestamp(), .timestamp_tz() methods.  The  
changes use the infrastructure of the .datetime() method and perform  
the datatype conversion as appropriate.  Unlike the .datetime()  
method, none of these methods accept a format template and use ISO  
DateTime format instead.  However, except for .date(), the  
date/time related methods take an optional precision to adjust the  
fractional seconds.  
  
Jeevan Chalke, reviewed by Peter Eisentraut and Andrew Dunstan.  
+T865   SQL/JSON item method: bigint()          YES   
+T866   SQL/JSON item method: boolean()         YES   
+T867   SQL/JSON item method: date()            YES   
+T868   SQL/JSON item method: decimal()         YES   
+T869   SQL/JSON item method: decimal() with precision and scale            YES   
+T870   SQL/JSON item method: integer()         YES   
+T871   SQL/JSON item method: number()          YES   
+T872   SQL/JSON item method: string()          YES   
+T873   SQL/JSON item method: time()            YES   
+T874   SQL/JSON item method: time_tz()         YES   
+T875   SQL/JSON item method: time precision            YES   
+T876   SQL/JSON item method: timestamp()           YES   
+T877   SQL/JSON item method: timestamp_tz()            YES   
+T878   SQL/JSON item method: timestamp precision           YES   

用法举例:

https://git.postgresql.org/gitweb/?p=postgresql.git;a=blobdiff;f=src/test/regress/expected/jsonb_jsonpath.out;h=e758d729f435187ee95cfaeb34a5b6011b27d36a;hp=6659bc9091ac04373bf3ce28b16d13bf6c036670;hb=66ea94e8e606529bb334515f388c62314956739e;hpb=924d046dcf55887c98a1628675a30f4b0eebe556

https://git.postgresql.org/gitweb/?p=postgresql.git;a=blobdiff;f=src/test/regress/expected/jsonpath.out;h=fd9bd755f520fecad84d6e23074f0633f44357ea;hp=eeffb38c1b690cbd8c122af5885e1c1624646e7f;hb=66ea94e8e606529bb334515f388c62314956739e;hpb=924d046dcf55887c98a1628675a30f4b0eebe556

digoal's wechat