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

  • Home
  • SEARCH
  • 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 6712787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:18:03+00:00 2026-05-26T08:18:03+00:00

create table date_dimension ( id serial primary key, date_id date, ….. others ); create

  • 0
create table date_dimension (
id serial primary key,
date_id date,
..... others
);

create table temp (
id serial primary key,
from_date integer,
to_date integer,
value integer,
foreign key (from_date, to_date) references date_dimension(id, id)
);  

How can I refer both from_date and to_date to id field in date_dimension?
The current code fails to do that saying

ERROR:  there is no unique constraint matching given keys for referenced table "date_dimension"  

Thank you

  • 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-26T08:18:03+00:00Added an answer on May 26, 2026 at 8:18 am

    each FOREIGN KEY constraint added to a table will always relate one row in the referencing table to one row* in the referant. If you want to have each row in the referencing to refer to two distinct rows in the referant, you need two, separate foreign key constraints.

    you want:

    foreign key (from_date) references date_dimension(id)
    foreign key (to_date) references date_dimension(id)
    

    You almost always want to have exactly the rows in the foreign key to be the same as the primary key in the referant.

    * Actually, there may be more than one row in the referant if the foreign key is smaller than a candidate key of the referant. this is seldom useful, though, and almost certainly unrelated to the problem you’re describing

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

Sidebar

Related Questions

I have a date_dimension table definition: CREATE TABLE date_dimension ( id integer primary key,
My table is: CREATE TABLE A( id serial NOT NULL, date timestamp without time
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
create table snippet( id int not null auto_increment, primary key(id), idlanguage int not null,
CREATE TABLE Posts { id INT PRIMARY KEY AUTO_INCREMENT, title VARCHAR(200), url VARCHAR(200) }
CREATE TABLE DEPARTMENTS (Department_Id varchar(5) Primary Key NOT NULL, Department_Name char(20) NOT NULL, Manager_Id
Unable to create table as oracle shows ' no matching unique or primary key
Two temp tables are created and then loaded...Here's the schema. Create table #SH ([date]
I have two tables with the following schema: CREATE TABLE sales_data ( sales_time date
batch create date table column type is BATCH_CREATED_DATE DATE NOT NULL With the data

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.