Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metabase: support information_schema._pg_expandarray #12204

Closed
neverchanje opened this issue Sep 11, 2023 · 1 comment · Fixed by #12448
Closed

Metabase: support information_schema._pg_expandarray #12204

neverchanje opened this issue Sep 11, 2023 · 1 comment · Fixed by #12448

Comments

@neverchanje
Copy link
Contributor

    SELECT 
      NULL AS TABLE_CAT, 
      n.nspname AS TABLE_SCHEM, 
      ct.relname AS TABLE_NAME, 
      a.attname AS COLUMN_NAME, 
      (
        information_schema._pg_expandarray(i.indkey)
      ).n AS KEY_SEQ, 
      ci.relname AS PK_NAME, 
      information_schema._pg_expandarray(i.indkey) AS KEYS, 
      a.attnum AS A_ATTNUM 
    FROM 
      pg_catalog.pg_class ct 
      JOIN pg_catalog.pg_attribute a ON (ct.oid = a.attrelid) 
      JOIN pg_catalog.pg_namespace n ON (ct.relnamespace = n.oid) 
      JOIN pg_catalog.pg_index i ON (a.attrelid = i.indrelid) 
      JOIN pg_catalog.pg_class ci ON (ci.oid = i.indexrelid) 
    WHERE 
      true 
      AND n.nspname = 'public' 
      AND ct.relname = 'sentences' 
      AND i.indisprimary

I have ensured that all features have been supported except _pg_expandarray. Popular PG-compatible databases all have supported it. This is the main blocker for Metabase to load RW schemas.

@xxchan
Copy link
Member

xxchan commented Sep 14, 2023

The definition in PG is
https://github.com/postgres/postgres/blob/e0b2eed047df9045664da6f724cb42c10f8b12f0/src/backend/catalog/information_schema.sql#L42C1-L50

/* Expand any 1-D array into a set with integers 1..N */
CREATE FUNCTION _pg_expandarray(IN anyarray, OUT x anyelement, OUT n int)
    RETURNS SETOF RECORD
    LANGUAGE sql STRICT IMMUTABLE PARALLEL SAFE
    AS 'select $1[s],
        s operator(pg_catalog.-) pg_catalog.array_lower($1,1) operator(pg_catalog.+) 1
        from pg_catalog.generate_series(pg_catalog.array_lower($1,1),
                                        pg_catalog.array_upper($1,1),
                                        1) as g(s)';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants