Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1A6346332F0; Mon, 20 Apr 2009 18:59:42 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16515-06; Mon, 20 Apr 2009 18:59:40 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f174.google.com (mail-fx0-f174.google.com [209.85.220.174]) by mail.postgresql.org (Postfix) with ESMTP id D806263329C; Mon, 20 Apr 2009 18:59:39 -0300 (ADT) Received: by fxm22 with SMTP id 22so2830261fxm.19 for ; Mon, 20 Apr 2009 14:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=hVH+FJ+AycL6CfJ0PVYCIVMN3B8igLvMXR5c8NzirjY=; b=vnmecWShepuhDmVOXsUJqCMzuzUkZkmgiQ0iWOFV+5Ve6disJwrmHtoOqSMd+lAXdg 11YgqWvxOBZw5uUoMuTL3/9QuXEPvL0cLifhUj85stRVyaPiwStJQ+sUgJiQaDo3dHDS TT2oXxbkZEyoqZOd06lf3txH/LZ/+ykk1vpDw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=tGmL6dItpZzmX43ONPsJK+ZkVf2TQ2TcvjoNIoIuXB+2OcNEvSIDcUApzg9WXbKIz/ 8+kyammPn+WevkWEnYSjjzXrvjLQXqVVyNiEzoFlH/DUpBmBtH7JiFW0x/uEqmg7xtRh ItJRZR31eMDwNnEWQ07QDj8e2eM6odElwOKp0= MIME-Version: 1.0 Received: by 10.103.229.12 with SMTP id g12mr3387246mur.16.1240264278798; Mon, 20 Apr 2009 14:51:18 -0700 (PDT) In-Reply-To: <41534c40904191403m2eeabc27tc4bc6ce206c87464@mail.gmail.com> References: <41534c40904191403m2eeabc27tc4bc6ce206c87464@mail.gmail.com> Date: Mon, 20 Apr 2009 17:51:18 -0400 Message-ID: Subject: Re: Postgresql 8.3X supports Arrays of Composite Types? From: Merlin Moncure To: Robson Fidalgo Cc: pgsql-docs@postgresql.org, pgsql-general@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200904/807 X-Sequence-Number: 146763 On Sun, Apr 19, 2009 at 5:03 PM, Robson Fidalgo wrote: > Until here is everything ok, but I have not success with insert values, then > I tried: > > 1)insert into person values ('Joe', '{("1","1111"),("2","2222") }'); > 2)insert into person values ('Joe', array[('1','1111'),('2','2222')]); > 3)insert into person values ('Joe', array[row('1','1111'),row('2','2222')]); > 4)insert into person values ('Joe', > _phone[phone('1','1111'),phone('2','2222')]);** > ** considering _phone = name of array type (automatically created by > postgres) and phone = name of composite type (also automatically created by > postgres) I agree with David -- arrays of composites should not be used in table definitions. There are exceptions, but you have to be very cautious. The phone number composite is basically ok, but I'd advise dropping the array minimum. Here are the basic problems: *) constraint checking vs. array of composites is problematic *) updating a specific field of a specific composite is not really possible...you have to build a complete new composite array and update the table with it. *) searching (who has a phone number x?) is a problem Imagine a client changes one of his/her phone numbers and compare the sql you would have to write doing it the classic way vs. your way. As David noted, if you like the composite format in the presentation of data, you can trivially do this in view. There may be reasons to do this -- the advantages of composite are convenience in passing data to/from functions and nesting data returned to the client. There is no disadvantage of nesting data 'in query' -- that's how I do it and it works very well. There are a couple of exceptions to the 'no arrays in table'. You may have a lot of static data (think float[]) that you are doing numerical analysis on the client for example. It only ever gets inserted/selected/deleted in bulk and never updated. There are other exceptions, but they are rare. Usually it's better doing it the 'sql way' merlin