File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 33
33
RAISE INFO E' GraphQL to parse:\n %\n ' , graphql_q;
34
34
SELECT * INTO STRICT sql_q FROM graphql .to_sql (graphql_q);
35
35
RAISE INFO E' SQL that will be run:\n %\n ' , sql_q;
36
- EXECUTE sql_q INTO STRICT result ;
36
+ result : = graphql . run (graphql_q) ;
37
37
RAISE INFO E' Result:\n %\n ' , result;
38
38
END
39
39
$$;
Original file line number Diff line number Diff line change @@ -131,14 +131,26 @@ RETURNS json AS $$
131
131
DECLARE
132
132
intermediate json;
133
133
result json[] = ARRAY[]::json[];
134
+ n integer = 0 ;
134
135
q text ;
135
136
BEGIN
136
137
FOR q IN SELECT graphql .to_sql (expr) LOOP
137
- EXECUTE q INTO intermediate;
138
- CONTINUE WHEN NOT FOUND;
138
+ n := n + 1 ;
139
+ BEGIN
140
+ EXECUTE q INTO STRICT intermediate;
141
+ EXCEPTION
142
+ WHEN NO_DATA_FOUND THEN CONTINUE;
143
+ END;
139
144
result := result || intermediate;
140
145
END LOOP;
141
- RETURN to_json(result);
146
+ -- - Maybe there is a better way to approach query cardinality? For example,
147
+ -- - by insisting that there be a root query (perhaps with no predicate?) or
148
+ -- - returning TABLE (result json).
149
+ IF n = 1 THEN
150
+ RETURN result[1 ];
151
+ ELSE
152
+ RETURN to_json(result);
153
+ END IF;
142
154
END
143
155
$$ LANGUAGE plpgsql STABLE STRICT;
144
156
You can’t perform that action at this time.
0 commit comments