Skip to content

Commit 96d8f29

Browse files
committed
Make pk a text array.
1 parent f1ec0e0 commit 96d8f29

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

graphql.sql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ DECLARE
146146
cols text[] = ARRAY[]::text[];
147147
col name;
148148
sub record;
149-
pk text = NULL;
149+
pk text[] = NULL;
150150
fks graphql.fk[];
151151
subselects text[] = ARRAY[]::text[];
152152
predicates text[] = ARRAY[]::text[];
153153
BEGIN
154154
body := btrim(body, '{}');
155155
IF predicate IS NOT NULL THEN
156+
SELECT array_agg(_) INTO STRICT pk
157+
FROM jsonb_array_elements_text(jsonb('['||predicate||']')) AS __(_);
156158
predicates := predicates
157-
|| graphql.format_comparison(tab,
158-
graphql.pk(tab),
159-
jsonb('['||predicate||']'));
159+
|| graphql.format_comparison(tab, graphql.pk(tab), pk);
160160
END IF;
161161
FOR sub IN SELECT * FROM graphql.parse_many(body) LOOP
162162
IF sub.predicate IS NOT NULL THEN
@@ -473,11 +473,10 @@ RETURNS text AS $$
473473
array_to_string((SELECT array_agg(col) FROM ys), ', '))
474474
$$ LANGUAGE sql STABLE STRICT;
475475

476-
CREATE FUNCTION format_comparison(x regclass, xs name[], ys jsonb)
476+
CREATE FUNCTION format_comparison(x regclass, xs name[], ys text[])
477477
RETURNS text AS $$
478478
WITH xs(col) AS (SELECT format('%I.%I', x, col) FROM unnest(xs) AS _(col)),
479-
named(col, txt) AS
480-
(SELECT * FROM ROWS FROM (unnest(xs), jsonb_array_elements_text(ys))),
479+
named(col, txt) AS (SELECT * FROM unnest(xs, ys)),
481480
casted(val) AS (SELECT format('%L::%I', txt, typ)
482481
FROM named JOIN graphql.cols(x) USING (col))
483482
SELECT format('(%s) = (%s)',

0 commit comments

Comments
 (0)