Skip to content

Commit f4e7cea

Browse files
committed
cast oids to bigint instead of int to avoid overflow
oids are 4 byte unsigned integers. ints are 4 bytes signed integers. This means some oids when cast to int are represented as negative values which are saved in the context json. When the Rust code tries to parse these negative values as a u32 (which is also an unsigned 4 byte value) it fails. Casting to bigint works around this because bigint is an 8 byte long signed integer and all of the oids fit withing the positive values range of a bigint.
1 parent db4c6ab commit f4e7cea

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

sql/load_sql_context.sql

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ schemas_with_privilege(oid, name) as (
88
-- irreleavnt tenants
99
-- https://github.com/supabase/pg_graphql/pull/480
1010
select
11-
pn.oid::int,
11+
pn.oid::bigint,
1212
pn.nspname::text
1313
from
1414
pg_namespace pn
@@ -45,8 +45,8 @@ select
4545
select
4646
pt.oid,
4747
jsonb_build_object(
48-
'oid', pt.oid::int,
49-
'schema_oid', min(pt.typnamespace)::int,
48+
'oid', pt.oid::bigint,
49+
'schema_oid', min(pt.typnamespace)::bigint,
5050
'name', min(pt.typname),
5151
'comment', pg_catalog.obj_description(pt.oid, 'pg_type'),
5252
'directives', jsonb_build_object(
@@ -55,7 +55,7 @@ select
5555
),
5656
'values', jsonb_agg(
5757
jsonb_build_object(
58-
'oid', pe.oid::int,
58+
'oid', pe.oid::bigint,
5959
'name', pe.enumlabel,
6060
'sort_order', (pe.enumsortorder * 100000)::int
6161
)
@@ -85,10 +85,10 @@ select
8585
(
8686
select
8787
jsonb_object_agg(
88-
pt.oid::int,
88+
pt.oid::bigint,
8989
jsonb_build_object(
90-
'oid', pt.oid::int,
91-
'schema_oid', pt.typnamespace::int,
90+
'oid', pt.oid::bigint,
91+
'schema_oid', pt.typnamespace::bigint,
9292
'name', pt.typname,
9393
'category', case
9494
when pt.typcategory = 'A' then 'Array'
@@ -99,9 +99,9 @@ select
9999
else 'Other'
100100
end,
101101
-- if category is 'Array', points at the underlying element type
102-
'array_element_type_oid', nullif(pt.typelem::int, 0),
102+
'array_element_type_oid', nullif(pt.typelem::bigint, 0),
103103
-- if category is 'Table' points to the table oid
104-
'table_oid', tabs.oid::int,
104+
'table_oid', tabs.oid::bigint,
105105
'comment', pg_catalog.obj_description(pt.oid, 'pg_type'),
106106
'permissions', jsonb_build_object(
107107
'is_usable', pg_catalog.has_type_privilege(current_user, pt.oid, 'USAGE')
@@ -122,8 +122,8 @@ select
122122
select
123123
jsonb_agg(
124124
jsonb_build_object(
125-
'oid', pt.oid::int,
126-
'schema_oid', pt.typnamespace::int
125+
'oid', pt.oid::bigint,
126+
'schema_oid', pt.typnamespace::bigint
127127
)
128128
)
129129
from
@@ -146,7 +146,7 @@ select
146146
jsonb_agg(
147147
jsonb_build_object(
148148
'local_table_meta', jsonb_build_object(
149-
'oid', pf.conrelid::int,
149+
'oid', pf.conrelid::bigint,
150150
'name', pa_local.relname::text,
151151
'is_rls_enabled', pa_local.relrowsecurity,
152152
'schema', pa_local.relnamespace::regnamespace::text,
@@ -162,7 +162,7 @@ select
162162
)
163163
),
164164
'referenced_table_meta', jsonb_build_object(
165-
'oid', pf.confrelid::int,
165+
'oid', pf.confrelid::bigint,
166166
'name', pa_referenced.relname::text,
167167
'is_rls_enabled', pa_referenced.relrowsecurity,
168168
'schema', pa_referenced.relnamespace::regnamespace::text,
@@ -202,9 +202,9 @@ select
202202
(
203203
select
204204
jsonb_object_agg(
205-
pn.oid::int,
205+
pn.oid::bigint,
206206
jsonb_build_object(
207-
'oid', pn.oid::int,
207+
'oid', pn.oid::bigint,
208208
'name', pn.name,
209209
'comment', pg_catalog.obj_description(pn.oid, 'pg_namespace'),
210210
'directives', jsonb_build_object(
@@ -230,15 +230,15 @@ select
230230
(
231231
select
232232
jsonb_object_agg(
233-
pc.oid::int,
233+
pc.oid::bigint,
234234
jsonb_build_object(
235-
'oid', pc.oid::int,
235+
'oid', pc.oid::bigint,
236236
'name', pc.relname::text,
237237
'relkind', pc.relkind::text,
238-
'reltype', pc.reltype::int,
238+
'reltype', pc.reltype::bigint,
239239
'is_rls_enabled', pc.relrowsecurity,
240240
'schema', schemas_.name,
241-
'schema_oid', pc.relnamespace::int,
241+
'schema_oid', pc.relnamespace::bigint,
242242
'comment', pg_catalog.obj_description(pc.oid, 'pg_class'),
243243
'directives', (
244244
with directives(directive) as (
@@ -267,7 +267,7 @@ select
267267
select
268268
jsonb_agg(
269269
jsonb_build_object(
270-
'table_oid', pi.indrelid::int,
270+
'table_oid', pi.indrelid::bigint,
271271
'column_names', coalesce(
272272
(
273273
select
@@ -296,13 +296,13 @@ select
296296
jsonb_agg(
297297
jsonb_build_object(
298298
'name', pa.attname::text,
299-
'type_oid', pa.atttypid::int,
299+
'type_oid', pa.atttypid::bigint,
300300
-- includes type mod info like char(4)
301301
'type_name', pg_catalog.format_type(pa.atttypid, pa.atttypmod),
302302
-- char, bpchar, varchar, char[], bpchar[], carchar[]
303303
-- the -4 removes the byte for the null terminated str
304304
'max_characters', nullif(pa.atttypmod, -1) - 4,
305-
'schema_oid', schemas_.oid::int,
305+
'schema_oid', schemas_.oid::bigint,
306306
'is_not_null', pa.attnotnull,
307307
'attribute_num', pa.attnum,
308308
'has_default', pd.adbin is not null, -- pg_get_expr(pd.adbin, pd.adrelid) shows expression
@@ -397,13 +397,13 @@ select
397397
select
398398
jsonb_agg(
399399
jsonb_build_object(
400-
'oid', pp.oid::int,
400+
'oid', pp.oid::bigint,
401401
'name', pp.proname::text,
402-
'type_oid', pp.prorettype::oid::int,
402+
'type_oid', pp.prorettype::bigint,
403403
'type_name', pp.prorettype::regtype::text,
404-
'schema_oid', pronamespace::int,
404+
'schema_oid', pronamespace::bigint,
405405
'schema_name', pronamespace::regnamespace::text,
406-
'arg_types', proargtypes::int[],
406+
'arg_types', proargtypes::bigint[],
407407
'arg_names', proargnames::text[],
408408
'arg_defaults', pg_get_expr(proargdefaults, 0)::text,
409409
'num_args', pronargs,

0 commit comments

Comments
 (0)