@@ -162,6 +162,7 @@ static Node *RewriteFuncExprCardinality(Node *node, void *context);
162162static Node * RewriteFuncExprArrayLength (Node * node , void * context );
163163static Node * RewriteFuncExprPostgisBytea (Node * node , void * context );
164164static Node * RewriteFuncExprTrigonometry (Node * node , void * context );
165+ static Node * RewriteFuncExprInverseTrigonometry (Node * node , void * context );
165166static Node * RewriteFuncExprJsonbArrayLength (Node * node , void * context );
166167static Node * RewriteFuncExprEncode (Node * node , void * context );
167168static Node * RewriteFuncExprDecode (Node * node , void * context );
@@ -258,16 +259,16 @@ static FunctionCallRewriteRuleByName BuiltinFunctionCallRewriteRulesByName[] =
258259
259260 /* degree variants of trigonometry functions */
260261 {
261- "pg_catalog" , "acosd" , RewriteFuncExprTrigonometry , 0
262+ "pg_catalog" , "acosd" , RewriteFuncExprInverseTrigonometry , 0
262263 },
263264 {
264- "pg_catalog" , "asind" , RewriteFuncExprTrigonometry , 0
265+ "pg_catalog" , "asind" , RewriteFuncExprInverseTrigonometry , 0
265266 },
266267 {
267- "pg_catalog" , "atand" , RewriteFuncExprTrigonometry , 0
268+ "pg_catalog" , "atand" , RewriteFuncExprInverseTrigonometry , 0
268269 },
269270 {
270- "pg_catalog" , "atan2d" , RewriteFuncExprTrigonometry , 0
271+ "pg_catalog" , "atan2d" , RewriteFuncExprInverseTrigonometry , 0
271272 },
272273 {
273274 "pg_catalog" , "cosd" , RewriteFuncExprTrigonometry , 0
@@ -2095,7 +2096,7 @@ RewriteFuncExprCardinality(Node *node, void *context)
20952096
20962097/*
20972098 * RewriteFuncExprTrigonometry rewrites several trigonometry
2098- * function calls by adding a degrees (..) call.
2099+ * function calls by adding a radians (..) call.
20992100 */
21002101static Node *
21012102RewriteFuncExprTrigonometry (Node * node , void * context )
@@ -2105,22 +2106,6 @@ RewriteFuncExprTrigonometry(Node *node, void *context)
21052106 /* find the no degrees variant */
21062107 switch (funcExpr -> funcid )
21072108 {
2108- case F_ACOSD :
2109- funcExpr -> funcid = F_ACOS ;
2110- break ;
2111-
2112- case F_ASIND :
2113- funcExpr -> funcid = F_ASIN ;
2114- break ;
2115-
2116- case F_ATAND :
2117- funcExpr -> funcid = F_ATAN ;
2118- break ;
2119-
2120- case F_ATAN2D :
2121- funcExpr -> funcid = F_ATAN2 ;
2122- break ;
2123-
21242109 case F_COSD :
21252110 funcExpr -> funcid = F_COS ;
21262111 break ;
@@ -2141,6 +2126,53 @@ RewriteFuncExprTrigonometry(Node *node, void *context)
21412126 elog (ERROR , "unexpected function ID in rewrite %d" , funcExpr -> funcid );
21422127 }
21432128
2129+ FuncExpr * radiansExpr = makeNode (FuncExpr );
2130+
2131+ radiansExpr -> funcid = F_RADIANS ;
2132+ radiansExpr -> funcresulttype = funcExpr -> funcresulttype ;
2133+ radiansExpr -> funcretset = false;
2134+ radiansExpr -> funcvariadic = false;
2135+ radiansExpr -> funcformat = COERCE_EXPLICIT_CALL ;
2136+ radiansExpr -> location = -1 ;
2137+ radiansExpr -> args = funcExpr -> args ;
2138+
2139+ funcExpr -> args = list_make1 ((Node * ) radiansExpr );
2140+ return (Node * ) funcExpr ;
2141+ }
2142+
2143+
2144+ /*
2145+ * RewriteFuncExprInverseTrigonometry rewrites several inverse
2146+ * trigonometry function calls by adding a degrees(..) call.
2147+ */
2148+ static Node *
2149+ RewriteFuncExprInverseTrigonometry (Node * node , void * context )
2150+ {
2151+ FuncExpr * funcExpr = castNode (FuncExpr , node );
2152+
2153+ /* find the no degrees variant */
2154+ switch (funcExpr -> funcid )
2155+ {
2156+ case F_ACOSD :
2157+ funcExpr -> funcid = F_ACOS ;
2158+ break ;
2159+
2160+ case F_ASIND :
2161+ funcExpr -> funcid = F_ASIN ;
2162+ break ;
2163+
2164+ case F_ATAND :
2165+ funcExpr -> funcid = F_ATAN ;
2166+ break ;
2167+
2168+ case F_ATAN2D :
2169+ funcExpr -> funcid = F_ATAN2 ;
2170+ break ;
2171+
2172+ default :
2173+ elog (ERROR , "unexpected function ID in rewrite %d" , funcExpr -> funcid );
2174+ }
2175+
21442176 FuncExpr * degreesExpr = makeNode (FuncExpr );
21452177
21462178 degreesExpr -> funcid = F_DEGREES ;
@@ -2155,7 +2187,6 @@ RewriteFuncExprTrigonometry(Node *node, void *context)
21552187}
21562188
21572189
2158-
21592190/*
21602191 * RewriteFuncExprPostgisBytea rewrites bytea(geometry) function calls into
21612192 * ST_AsWKB(..) function calls to push down (implicit) casts.
0 commit comments