Re: array support patch phase 1 patch - Mailing list pgsql-patches

From Kris Jurka
Subject Re: array support patch phase 1 patch
Date
Msg-id Pine.LNX.4.33.0306020916590.23304-100000@leary.csoft.net
Whole thread Raw
In response to Re: array support patch phase 1 patch  (Joe Conway <mail@joeconway.com>)
Responses Re: array support patch phase 1 patch  (Joe Conway <mail@joeconway.com>)
List pgsql-patches
I've been looking at using the new array support with the JDBC driver to
retrieve foreign key information and I've kind of gotten stuck.

The basic query I want to run is

SELECT
        pkn.nspname AS PKTABLE_SCHEM,
        pkt.relname AS PKTABLE_NAME,
        pka.attname AS PKCOLUMN_NAME,
        fkn.nspname AS FKTABLE_SCHEM,
        fkt.relname AS FKTABLE_NAME,
        fka.attname AS FKCOLUMN_NAME,
        c.conname AS FK_NAME,
        pkc.conname AS PK_NAME

FROM pg_namespace pkn, pg_class pkt, pg_attribute pka,
        pg_namespace fkn, pg_class fkt, pg_attribute fka,
        pg_constraint c, pg_constraint pkc

WHERE
        pkn.oid = pkt.relnamespace
        AND pkt.oid = pka.attrelid
        AND fkn.oid = fkt.relnamespace
        AND fkt.oid = fka.attrelid
        AND c.conrelid = fkt.oid
        AND c.confrelid = pkt.oid
        AND pka.attnum = ANY (c.confkey)
        AND fka.attnum = ANY (c.conkey)
        AND c.confrelid = pkc.conrelid
--      AND pkc.conkey = c.confkey
;

So I'm getting back the right column and table names, but for a
multi-column key you get a cartesian product because you can't join on
index(conkey) = index(confkey).

I was trying formulate a way to make a function which will explode an
array into a resultset composed of the index and value.  So '{3,4,7}'
would become

index    value
1    3
2    4
3    7

I suppose you'd really want something like:

CREATE TABLE t (
    a int primary key,
    b int[]
);

SELECT * FROM explode_index(t,a,b);

returning rows of a, b-index, b-value

Another unrelated issue I ran into was that I wanted an equality operator
that was not ordered, so [1,2,3] = [2,1,3] because they contain the same
elements.


Just one user's thoughts,
Kris Jurka



pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Start-scripts linux
Next
From: Joe Conway
Date:
Subject: Re: array support patch phase 1 patch