Re: array support patch phase 1 patch

From: Kris Jurka <books(at)ejurka(dot)com>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Patches (PostgreSQL)" <pgsql-patches(at)postgresql(dot)org>
Subject: Re: array support patch phase 1 patch
Date: 2003-06-02 14:09:02
Message-ID: Pine.LNX.4.33.0306020916590.23304-100000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Joe Conway 2003-06-02 15:01:00 Re: array support patch phase 1 patch
Previous Message Bruce Momjian 2003-06-02 13:47:25 Re: Start-scripts linux