Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 330643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:42:01+00:00 2026-05-12T09:42:01+00:00

I want a bijection between the pair (tag1, tag2) and tag_id. CREATE TABLE tags

  • 0

I want a bijection between the pair (tag1, tag2) and tag_id.

CREATE TABLE tags (
         question_id INTEGER NOT NULL,
         tag_id SERIAL NOT NULL,
         tag1 VARCHAR(20),
         tag2 VARCHAR(20),
         PRIMARY KEY(question_id, tag_id),
         (tag1, tag2) UNIQUE references tags(tag_id)          #How?
     );

I want no reference such as:

(PHP, Perl) points to 1 and 2,
3 points to (C#, null) and (Python, Elinks)

In other words, I want the REFERENCE to be unique FROM (tag1, tag2) TO tags(tag_id), not UNIQUE(tag1, tag2).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:42:02+00:00Added an answer on May 12, 2026 at 9:42 am

    This might be more like what you are looking for:

    CREATE TABLE tags (
        question_id INTEGER NOT NULL,
        tag_id SERIAL NOT NULL,
        tag1 VARCHAR(20),
        tag2 VARCHAR(20),
        PRIMARY KEY (tag_id),
        INDEX (question_id),
        UNIQUE (tag1, tag2)
    );
    

    Making ‘tag_id’ the primary key means that you can only have one entry with a given ‘tag_id’, and that searches based on ‘tag_id’ will be fast.

    The index on ‘question_id’ will improve search speed based on ‘question_id’, which is what I think you were trying to do with your original PRIMARY KEY definition. If you really want the (tag_id, question_id) pair to be unique, as you had it, then add a UNIQUE (tag_id, question_id) in there, but I would say that you should leave tag_id as the primary key.

    The uniqueness constraint on (tag1, tag2) prevents the reverse mapping from having duplicates.

    Here are a few examples of what can work:

    Works:

    1 -> (x, y)

    2 -> (x, z)

    Fails (tag_id is a primary key, and therefore is unique):

    1 -> (x, y)

    1 -> (y, x)

    Fails (the pair (tag1, tag2) is not unique):

    1 -> (x, y)

    2 -> (x, y)

    However, the pair (x, y) is not equal to the pair (y, x). I’m not sure how to catch that uniqueness constraint.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to create a temporary table that has an auto_increment field plus a field
Want to create web sites with data on Dynamics AX. We want not to
Want the function to sort the table by HP but if duplicate HPs then
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
what I want to do is to create an algorithm, able to find all
Want make a mind map like the following: Image link is not available anymore.
want my table to show up only half way from the bottom of the
want to drag element to specific div and if not dragged to this div
Want to clear some concepts about SQL internals. Suppose I have a table as:
Want to merge [1,3,4], [2,5] -> [1,2,3,4,5] and zip [1,2,3],[4,5] -> [{1,4},{2,5}]. Its not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.