Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A5727B5DBC6 for ; Mon, 13 Jun 2011 16:09:09 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 63629-07 for ; Mon, 13 Jun 2011 19:09:03 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zebedee.cranntara.net (zebedee.cranntara.net [91.186.7.79]) by mail.postgresql.org (Postfix) with ESMTP id 84A66B5D80A for ; Mon, 13 Jun 2011 16:09:02 -0300 (ADT) Received: from [88.210.188.180] (helo=bolek.coachhouse) by zebedee.cranntara.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1QWCVN-0001zD-7p for pgsql-sql@postgresql.org; Mon, 13 Jun 2011 20:08:59 +0100 Received: from dick.coachhouse ([192.168.1.32] ident=tarlika) by bolek.coachhouse with esmtp (Exim 4.69) (envelope-from ) id 1QWCQz-0006HU-Ou for pgsql-sql@postgresql.org; Mon, 13 Jun 2011 20:04:26 +0100 Date: Mon, 13 Jun 2011 20:04:54 +0100 From: Tarlika Elisabeth Schmitz To: pgsql-sql@postgresql.org Subject: extract some column/value pairs via hstore Message-ID: <20110613200454.2a903880@dick.coachhouse> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.20.1; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/45 X-Sequence-Number: 35511 In a PL/pgSQL function, I need to extract column/value pairs from a table ignoring some of the columns. The excluded column names have previously been stored in an array "ak", which contains array['country_fk', 'region_fk', 'id'] SELECT key, value FROM ( SELECT (each(hstore(town))).* FROM town ) AS nk WHERE key NOT IN (SELECT unnest(ak)); ===== The above statement produces the desired result but it seems a bit convoluted. Can this be done in a more elegant way? ===== PostgreSQL 8.4 example: CREATE TABLE town ( country_fk character varying(3) NOT NULL, region_fk character varying(3) NOT NULL, id serial NOT NULL, "name" character varying(50) NOT NULL, source character varying(2) NOT NULL ) -- Best Regards, Tarlika Elisabeth Schmitz