Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cteon-0000Tc-S7 for pgsql-sql@arkaria.postgresql.org; Thu, 30 Mar 2017 18:29:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cteon-00019v-3T for pgsql-sql@arkaria.postgresql.org; Thu, 30 Mar 2017 18:29:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cteom-00019A-A1 for pgsql-sql@postgresql.org; Thu, 30 Mar 2017 18:29:08 +0000 Received: from mail-oi0-x22c.google.com ([2607:f8b0:4003:c06::22c]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cteoj-0002bi-Nk for pgsql-sql@postgresql.org; Thu, 30 Mar 2017 18:29:07 +0000 Received: by mail-oi0-x22c.google.com with SMTP id o67so39595233oib.1 for ; Thu, 30 Mar 2017 11:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=chZXREIXdcFwPV52jO1IYzX7PsMVmCEux5kFDlhOVZw=; b=hJrzQAuuP/vtaQn7SCr1+LFhLVNMdGtnpKpbEGHQy1fKdxWbbM7rhgfJ8olSMXqliL /8dEItwe1Fet1uvw1e5ydlxTqu26tyCLP4IT9aVqPRMshrIu6JnDFKnO+/KeMIeDujK0 qmGXPz0iQnOiUH9U64oM0Nkphj3uGtpSdE2/lmIvncu6MiV7Oaldgg2GnEgXmzR+WrPO hiPW7h1je7o9oQXGP4CTLUiwg1eMyPG7n1dqhXFIm5ZXD3Kkoa/LdVgLzukqgLZBP8aK sPf7j0KNpiP3m8daaEgmWS9ZTixVq54abwMC/I6t8nyX4wK2bv3kQpl//m1OW2E1EEp0 LDmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=chZXREIXdcFwPV52jO1IYzX7PsMVmCEux5kFDlhOVZw=; b=nK6coPfxsVFriYeVrF/oj7umtVswKgX+6gGDSaHJWoh9qSnVuGXVrLb/F64xKdARJd EscMDGc0VzZxwZFXYjoHGkHQwyNti+e08Y9HdooN5CNA5I1npeAMfzDdoiqCF3GQcy1S x9VSWMzAdoA2YRQeWr7B6kshPyQpFlx0xaNIGkmMywH1T5SfBxmHj5o7LK5NJd87dOd9 Tm8mKPCcCAXXSvYYcO3eI97TTFhlOhZ6zk6omNWVCFzQMtRdFQRY1HNz5fS0O423J82h akauf8qJL2kwrXlbkKcuZtFo4656J4RDgg5i+sZwdD6bRvkFyRKsQCTJdkcJtq/OGDjS C7PQ== X-Gm-Message-State: AFeK/H3TdFusNA1bQN8xbwhwPBRAc6OZ6QOXqjku/6bvUV8cM0gtfSYzGUUnuuwXvaC9HA== X-Received: by 10.157.80.20 with SMTP id a20mr766831oth.89.1490898544867; Thu, 30 Mar 2017 11:29:04 -0700 (PDT) Received: from [127.0.0.1] (mail.jonesborocwl.org. [64.233.145.118]) by smtp.gmail.com with ESMTPSA id s67sm1362639ois.11.2017.03.30.11.29.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 11:29:04 -0700 (PDT) Subject: Re: Query Advice To: pgsql-sql@postgresql.org References: From: Jason Aleski Message-ID: <9b898bec-bc88-f67e-e327-4c04fd169100@gmail.com> Date: Thu, 30 Mar 2017 13:27:27 -0500 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org I agree, depends what the application is expecting, but if you only wanted to return each field, would a regular JOIN work? This should return each field in a separate column. SELECT t1.name, t2.description, t2.addr, t2.city, t2.stprov, t2.zip FROM company t1 JOIN postal_addresses AS t2 ON t1.company_id=t2.company_id WHERE t1.company_id=1731; -JA- On 3/30/2017 1:03 PM, Gary Chambers wrote: > All, > > Given the following tables: > > company > ------- > company_id > name > > postal_addresses > ---------------- > postal_address_id > company_id > description > addr > city > stprov > zip > > > I've been handling joins as such: > > select c.company_id, > array(select concat_ws('|', pa.description, pa.addr, pa.city, > pa.stprov, pa.zip) > ) addrs > from companies c inner join postal_addresses pa using (company_id) > where company_id = 1731; > > Is there a better way to get the company information along with all of > the > addresses in a single query? This works, but it requires the additional > step of splitting the addresses by the the delimiter at the application > layer. > > Thanks for any advice you have. > > -- > G. > > -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql