Search Postgresql Archives

Re: arrays of foreign keys

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/07/07 18:47, Max wrote:
> Hello,
> 
> And pardon me if I posted this question to the wrong list, it seems
> this list is the most appropriate.
> 
> I am trying to create a table with an array containing foreign keys.
> I've searched through the documentation and couldn't find a way to do
> so.
> 
> Is this something that one can do?
> 
> Basically, I have two tables:
> 
> create table user (
>   user_id serial,
>   login varchar(50) primary key,
>   tags integer[]-- this is where the problem lies
> );
> 
> create table tag (
>   tag_id serial,
>   name varchar(50) primary key
> );
> 
> I would like the user.tags field to be a list of foreign keys (tag_ids
> specifically).
> 
> I know I can solve my problem with the following table:
> 
> create table user_tag (
>   user_id integer,
>   tag_id integer,
>   foreign key (user_id) references table user(user_id) on delete
> cascade,
>   foreign key (tag_id) references table tag(tag_id) on delete cascade,
>   primary key (user_id,tag_id)
> );
> 
> But I would really like to avoid doing that.

Why?

The (literally) cardinal rule of database normalization is
"eliminate repeating values".

> Is there a solution to this problem with arrays of foreign keys, and
> if so, how does one do that?
> 
> Thanks for any help.

- --
Ron Johnson, Jr.
Jefferson LA  USA

Give a man a fish, and he eats for a day.
Hit him with a fish, and he goes away for good!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFG5UDUS9HxQb37XmcRAo+WAKDSB8DNYBZiZtOJ3utAkkX9QkDYtACgk0ab
HKf6Oe1DbvZP8cmh1e9dZaQ=
=lPTU
-----END PGP SIGNATURE-----

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[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