title: Insert multiple values with foreign key Postgresql
body: <p>I am having trouble figuring out how to insert multiple values to a table, which checks if another table has the needed values stored. I am currently doing this in a PostgreSQL server, but will be implementing it in PreparedStatements for my java program.</p>
  
  <p>user_id is a foreign key which references the primary in mock2. I have been trying to check if mock2 has values ('foo1', 'bar1') and ('foo2', 'bar2').</p>
  
  <p>After this I am trying to insert new values into mock1 which would have a date and integer value and reference the primary key of the row in mock2 to the foreign key in mock1.</p>
  
  <p>mock1 table looks like this:</p>
  
  <pre><code>===============================
  | date  |  time    |  user_id |
  | date  |  integer |  integer | 
  |       |          |          |
  </code></pre>
  
  <p>And the table mock2 is:</p>
  
  <pre><code>==================================
  | Id      |  name   |  program   |
  | integer |  text   |  test      |
  </code></pre>
  
  <p>Id is a primary key for the table and the name is UNIQUE.</p>
  
  <p>I've been playing around with this solution <a href="https://dba.stackexchange.com/questions/46410/how-do-i-insert-a-row-which-contains-a-foreign-key">https://dba.stackexchange.com/questions/46410/how-do-i-insert-a-row-which-contains-a-foreign-key</a></p>
  
  <p>However, I haven't been able to make it work. Could someone please point out what the correct syntax is for this, I would be really appreciative. </p>
  
  <p>EDIT:</p>
  
  <p>The create table statements are: </p>
  
  <pre><code>CREATE TABLE mock2(
     id SERIAL PRIMARY KEY UNIQUE,
     name text NOT NULL,
      program text NOT NULL UNIQUE
  );
  </code></pre>
  
  <p>and </p>
  
  <pre><code>CREATE TABLE mock1(
     date date,
     time_spent INTEGER,
     user_id integer REFERENCES mock2(Id) NOT NULL);
  </code></pre>