0

Let's say I have an email with the tags 'inbox', 'unread', 'friend' and their tag id is 1,2,3. In my database I have something like

create email(emailID serial, header_data text, body text, tags int[])

I'd like to search my inbox for everything with tagid 2. The email I want will have the tags value as [1,2,3]. How do I create an index so this email is included? I'm using C# but I don't think that matters.

  • 2
    You should normalize your tables instead – Neil McGuigan Apr 04 '17 at 18:16
  • http://www.databasesoup.com/2015/01/tag-all-things.html –  Apr 04 '17 at 20:03
  • This might be the answer you are looking for: http://stackoverflow.com/questions/4058731/can-postgresql-index-array-columns – berlinguyinca Apr 04 '17 at 20:13
  • @NeilMcGuigan: IDK what retards upvoted you but it's literally [the worse method according to the benchmarks horse linked](http://www.databasesoup.com/2015/01/tag-all-things-part-2.html). People shouldn't leave comments when they don't know the consequences of their suggestions. –  Apr 05 '17 at 06:32
  • @acidzombie24 you sweet summer child. If performance was the only concern, you'd write everything in assembly. – Neil McGuigan Apr 05 '17 at 16:54
  • @NeilMcGuigan: Haha you got me there. IMO my layout is the most simple way and I always hated making a table just to link up a one to many relationship. However I don't think I should do it the way you suggest unless there's a good reason and because people typically do it that way isn't a good reason (people still use old version of software too) –  Apr 05 '17 at 19:41

0 Answers0