Fix overloading of functions with unnamed arguments (specifically for prefer params=single-object)
This commit is contained in:
committed by
Steve Chavez
parent
b091586394
commit
e08bb3a197
@@ -25,6 +25,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- #1585, Fix error messages on connection failure for localized postgres on Windows - @wolfgangwalther
|
||||
- #1636, Fix `application/octet-stream` appending `charset=utf-8` - @steve-chavez
|
||||
- #1615, Fix RPC return type handling and embedding for domains with composite base type - @wolfgangwalther
|
||||
- #1469, Fix overloading of functions with unnamed arguments - @wolfgangwalther
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ decodeProcs =
|
||||
parseArgs :: Text -> [PgArg]
|
||||
parseArgs = mapMaybe parseArg . filter (not . isPrefixOf "OUT" . toS) . map strip . split (==',')
|
||||
|
||||
-- TODO: does parseArg properly handle unnamed "character varying" arguments or arguments with spaces in their names?
|
||||
parseArg :: Text -> Maybe PgArg
|
||||
parseArg arg =
|
||||
let isVariadic = isPrefixOf "VARIADIC " $ toS arg
|
||||
@@ -161,7 +162,9 @@ decodeProcs =
|
||||
(body, def) = breakOn " DEFAULT " argNoMode
|
||||
(name, typ) = breakOn " " body in
|
||||
if T.null typ
|
||||
then Nothing
|
||||
-- Handle unnamed args. TODO: refactor to types
|
||||
then Just $
|
||||
PgArg mempty (strip name) (T.null def) isVariadic
|
||||
else Just $
|
||||
PgArg (dropAround (== '"') name) (strip typ) (T.null def) isVariadic
|
||||
|
||||
|
||||
@@ -284,6 +284,19 @@ spec actualPgVersion =
|
||||
[json|null|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
context "different types when overloaded" $ do
|
||||
it "returns composite type" $
|
||||
post "/rpc/ret_point_overloaded" [json|{"x": 1, "y": 2}|] `shouldRespondWith`
|
||||
[json|[{"x": 1, "y": 2}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "returns json scalar with prefer single object" $
|
||||
request methodPost "/rpc/ret_point_overloaded" [("Prefer","params=single-object")]
|
||||
[json|{"x": 1, "y": 2}|]
|
||||
`shouldRespondWith`
|
||||
[json|{"x": 1, "y": 2}|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
context "proc argument types" $ do
|
||||
-- different syntax for array needed for pg<10
|
||||
when (actualPgVersion < pgVersion100) $
|
||||
|
||||
Vendored
+8
@@ -983,6 +983,14 @@ create function test.ret_point_2d() returns test.point_2d as $$
|
||||
select row(10, 5)::test.point_2d;
|
||||
$$ language sql;
|
||||
|
||||
create function test.ret_point_overloaded(x int, y int) returns test.point_2d as $$
|
||||
select row(x, y)::test.point_2d;
|
||||
$$ language sql;
|
||||
|
||||
create function test.ret_point_overloaded(json) returns json as $$
|
||||
select $1;
|
||||
$$ language sql;
|
||||
|
||||
-- domains on composite types are only supported from pg 11 on
|
||||
do $do$begin
|
||||
if (SELECT current_setting('server_version_num')::int >= 110000) then
|
||||
|
||||
Reference in New Issue
Block a user