Skip to content

Commit 6f17faf

Browse files
committed
refactor: remove character varying casting
1 parent 7629eff commit 6f17faf

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/PostgREST/Query/SqlFragment.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ asCsvF = asCsvHeaderF <> " || '\n' || " <> asCsvBodyF
180180

181181
asJsonF :: Bool -> SqlFragment
182182
asJsonF returnsScalar
183-
| returnsScalar = "coalesce(json_agg(_postgrest_t.pgrst_scalar), '[]')::character varying"
184-
| otherwise = "coalesce(json_agg(_postgrest_t), '[]')::character varying"
183+
| returnsScalar = "coalesce(json_agg(_postgrest_t.pgrst_scalar), '[]')"
184+
| otherwise = "coalesce(json_agg(_postgrest_t), '[]')"
185185

186186
asJsonSingleF :: Bool -> SqlFragment
187187
asJsonSingleF returnsScalar
188-
| returnsScalar = "coalesce((json_agg(_postgrest_t.pgrst_scalar)->0)::text, 'null')"
189-
| otherwise = "coalesce((json_agg(_postgrest_t)->0)::text, 'null')"
188+
| returnsScalar = "coalesce(json_agg(_postgrest_t.pgrst_scalar)->0, 'null')"
189+
| otherwise = "coalesce(json_agg(_postgrest_t)->0, 'null')"
190190

191191
asXmlF :: FieldName -> SqlFragment
192192
asXmlF fieldName = "coalesce(xmlagg(_postgrest_t." <> pgFmtIdent fieldName <> "), '')"

test/spec/Feature/Query/PlanSpec.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ spec actualPgVersion = do
5555
totalCost `shouldBe`
5656
if actualPgVersion > pgVersion120
5757
then 24.28
58-
else 32.28
58+
else 32.27
5959

6060
it "outputs blocks info when using the buffers option" $
6161
if actualPgVersion >= pgVersion130
@@ -126,8 +126,8 @@ spec actualPgVersion = do
126126
resHeaders `shouldSatisfy` elem ("Content-Type", "application/vnd.pgrst.plan+json; for=\"application/json\"; options=verbose; charset=utf-8")
127127
aggCol `shouldBe`
128128
if actualPgVersion >= pgVersion120
129-
then Just [aesonQQ| "(COALESCE(json_agg(ROW(projects.id, projects.name, projects.client_id)), '[]'::json))::character varying" |]
130-
else Just [aesonQQ| "(COALESCE(json_agg(ROW(pgrst_source.id, pgrst_source.name, pgrst_source.client_id)), '[]'::json))::character varying" |]
129+
then Just [aesonQQ| "COALESCE(json_agg(ROW(projects.id, projects.name, projects.client_id)), '[]'::json)" |]
130+
else Just [aesonQQ| "COALESCE(json_agg(ROW(pgrst_source.id, pgrst_source.name, pgrst_source.client_id)), '[]'::json)" |]
131131

132132
it "outputs the plan for application/vnd.pgrst.object " $ do
133133
r <- request methodGet "/projects_view" (acceptHdrs "application/vnd.pgrst.plan+json; for=\"application/vnd.pgrst.object\"; options=verbose") ""
@@ -139,8 +139,8 @@ spec actualPgVersion = do
139139
resHeaders `shouldSatisfy` elem ("Content-Type", "application/vnd.pgrst.plan+json; for=\"application/vnd.pgrst.object+json\"; options=verbose; charset=utf-8")
140140
aggCol `shouldBe`
141141
if actualPgVersion >= pgVersion120
142-
then Just [aesonQQ| "COALESCE(((json_agg(ROW(projects.id, projects.name, projects.client_id)) -> 0))::text, 'null'::text)" |]
143-
else Just [aesonQQ| "COALESCE(((json_agg(ROW(pgrst_source.id, pgrst_source.name, pgrst_source.client_id)) -> 0))::text, 'null'::text)" |]
142+
then Just [aesonQQ| "COALESCE((json_agg(ROW(projects.id, projects.name, projects.client_id)) -> 0), 'null'::json)" |]
143+
else Just [aesonQQ| "COALESCE((json_agg(ROW(pgrst_source.id, pgrst_source.name, pgrst_source.client_id)) -> 0), 'null'::json)" |]
144144

145145
describe "writes plans" $ do
146146
it "outputs the total cost for an insert" $ do
@@ -205,7 +205,7 @@ spec actualPgVersion = do
205205

206206
liftIO $ do
207207
resHeaders `shouldSatisfy` elem ("Content-Type", "application/vnd.pgrst.plan+json; for=\"application/vnd.pgrst.object+json\"; options=verbose; charset=utf-8")
208-
aggCol `shouldBe` Just [aesonQQ| "COALESCE(((json_agg(ROW(projects.id, projects.name, projects.client_id)) -> 0))::text, 'null'::text)" |]
208+
aggCol `shouldBe` Just [aesonQQ| "COALESCE((json_agg(ROW(projects.id, projects.name, projects.client_id)) -> 0), 'null'::json)" |]
209209

210210
describe "function plan" $ do
211211
it "outputs the total cost for a function call" $ do
@@ -219,7 +219,7 @@ spec actualPgVersion = do
219219
liftIO $ do
220220
resHeaders `shouldSatisfy` elem ("Content-Type", "application/vnd.pgrst.plan+json; charset=utf-8")
221221
resStatus `shouldBe` Status { statusCode = 200, statusMessage="OK" }
222-
totalCost `shouldBe` 68.57
222+
totalCost `shouldBe` 68.56
223223

224224
it "outputs the plan for text/xml" $ do
225225
r <- request methodGet "/rpc/return_scalar_xml"

0 commit comments

Comments
 (0)