X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 055F49FA5C9 for ; Wed, 28 Jun 2006 12:04:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82040-02 for ; Wed, 28 Jun 2006 12:03:52 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by postgresql.org (Postfix) with ESMTP id 7A4189FA5BA for ; Wed, 28 Jun 2006 12:03:49 -0300 (ADT) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id k5SFH5Va009188; Wed, 28 Jun 2006 18:17:05 +0300 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id k5SFH0oH009184; Wed, 28 Jun 2006 18:17:03 +0300 Date: Wed, 28 Jun 2006 18:17:00 +0300 (EEST) From: Achilleus Mantzios To: Rodrigo Sakai cc: pgsql-sql@postgresql.org Subject: Re: RES: Joins between int and int[] In-Reply-To: <002501c69abf$84d524f0$4700a8c0@TREEZANTHUS> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/296 X-Sequence-Number: 25532 O Rodrigo Sakai έγραψε στις Jun 28, 2006 : > Thanks Mantzios, your answer helped a lot! But I have a lot of multi column > foreign keys! Any other ideia?? > You must use/write a function that takes as an argument an array and returns the elements of this array as a set. I dont recall if some function like that exists in contrib but you could search in the archives. Also if my memory serves well there was a similar talk in th -sql list some months ago. Also keep in mind that if your queries are standardized then you can write a program in C/perl/java/php/... that does what you want. If your queries are ad-hoc then go the first approach. > Thanks in advance! > > > -----Mensagem original----- > De: Achilleus Mantzios [mailto:achill@matrix.gatewaynet.com] > Enviada em: quarta-feira, 28 de junho de 2006 04:01 > Para: Rodrigo Sakai > Assunto: Re: [SQL] Joins between int and int[] > > O Rodrigo Sakai έγραψε στις Jun 27, 2006 : > > > Hi, > > > > > > > > I want to use the system catalog tables/views to query some things, and > > one of the queries I have to do is joining pg_attribute and pg_constraint > to > > know what constraint belongs to which table.attribute. My question is how > > can I write the join clause between a int (pg_attribute.attnum) and int[ ] > > (pg_constraint.conkey). > > Are you having tables with multi column foreign keys? > e.g. (a,b) REFERENCES partable(para,parb). > > If not then join with pg_constraint.conkey[1], > if yes then the problem becomes a little less trivial. > > > > > > > > > > > > > The query is: > > > > > > > > select relname, attname, attnotnull, atthasdef > > > > from pg_class as pc > > > > inner join pg_attribute as pa > > > > on pc.oid=pa.attrelid > > > > inner join pg_constraint pcons > > > > on pc.oid=pcons.conrelid > > > > and pa.attnum = pcons.conkey -------> the problem > > > > > > > > > > > > Thanks!!! > > > > > > > > > > -- -Achilleus