Skip to content

Commit 26bafaf

Browse files
committed
fix: table_id types mismatch
Apparently Postgres converts oid to string when converting to JSON, so we have to explicitly cast table_id columns to type int8.
1 parent eb42a19 commit 26bafaf

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

src/lib/sql/columns.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SELECT
2-
c.oid AS table_id,
2+
c.oid :: int8 AS table_id,
33
table_schema AS schema,
44
table_name AS table,
55
(c.oid || '.' || ordinal_position) AS id,

src/lib/sql/grants.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SELECT
2-
c.oid AS table_id,
2+
c.oid :: int8 AS table_id,
33
grantor,
44
grantee,
55
table_catalog AS catalog,
@@ -10,5 +10,5 @@ SELECT
1010
with_hierarchy :: boolean
1111
FROM
1212
information_schema.role_table_grants
13-
JOIN pg_class c ON quote_ident(table_schema)::regnamespace = c.relnamespace
13+
JOIN pg_class c ON quote_ident(table_schema) :: regnamespace = c.relnamespace
1414
AND table_name = c.relname

src/lib/sql/policies.sql

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@ select
22
pol.oid as id,
33
n.nspname AS schema,
44
c.relname AS table,
5-
c.oid AS table_id,
5+
c.oid :: int8 AS table_id,
66
pol.polname AS name,
77
CASE
88
WHEN pol.polpermissive THEN 'PERMISSIVE' :: text
99
ELSE 'RESTRICTIVE' :: text
1010
END AS action,
1111
CASE
12-
WHEN pol.polroles = '{0}' :: oid []
13-
THEN array_to_json(string_to_array('public' :: text, '' :: text) :: name [])
14-
ELSE array_to_json(ARRAY(
15-
SELECT
16-
pg_authid.rolname
17-
FROM
18-
pg_authid
19-
WHERE
20-
pg_authid.oid = ANY (pol.polroles)
21-
ORDER BY
22-
pg_authid.rolname
23-
))
12+
WHEN pol.polroles = '{0}' :: oid [] THEN array_to_json(
13+
string_to_array('public' :: text, '' :: text) :: name []
14+
)
15+
ELSE array_to_json(
16+
ARRAY(
17+
SELECT
18+
pg_authid.rolname
19+
FROM
20+
pg_authid
21+
WHERE
22+
pg_authid.oid = ANY (pol.polroles)
23+
ORDER BY
24+
pg_authid.rolname
25+
)
26+
)
2427
END AS roles,
2528
CASE
2629
pol.polcmd
@@ -36,4 +39,4 @@ select
3639
FROM
3740
pg_policy pol
3841
JOIN pg_class c ON c.oid = pol.polrelid
39-
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
42+
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace

src/lib/sql/primary_keys.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SELECT
22
n.nspname AS schema,
33
c.oid :: regclass AS table_name,
44
a.attname AS name,
5-
c.oid AS table_id
5+
c.oid :: int8 AS table_id
66
FROM
77
pg_index i,
88
pg_class c,

0 commit comments

Comments
 (0)