Search Postgresql Archives

Re: Working with Array of Composite Type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On March 28, 2015 06:18:49 PM Alex Magnum wrote:
> Hello,
> I am struggling with finding the right way to deal with arrays of composite
> types. Bellow is an example of the general setup where I defined an image
> type to describe the image properties. A user can have mulitple images
> stored.

The canonical answer is that in almost all cases where you think you want an 
array of composites, you *really* want a table join:

i.e. turn your image *type* into an image *table* with the user_id as a 
foreign key.

CREATE TABLE users (
  user_id           serial NOT NULL,
);

CREATE TABLE image (
  id                smallint,
  user_id     int references users (user_id)
  caption           text,
  is_primary        boolean,
  is_private        boolean
);




-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux