title: Why is json_populate_record() not recognizing row type?
body: <p>I have 2 tables <code>type</code> and <code>name</code>. I am trying to insert into these with json_populate_record() through a function. Receiving the following error:</p>
  
  <pre><code>first argument of json_populate_record must be a row type
  </code></pre>
  
  <p>Table <code>type</code> is created using:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS "type" (
    "id"    TEXT NOT NULL,
    "value" TEXT NOT NULL,
    PRIMARY KEY ("id"),
    CHECK ("id"&lt;&gt;'' AND "value"&lt;&gt;'')
  );
  CREATE INDEX IF NOT EXISTS "idx_type_value"
  ON "type" ("value");
  
  
  CREATE OR REPLACE FUNCTION "type_insertone" (
    IN _a JSON
  ) RETURNS VOID AS $$
  BEGIN
    INSERT INTO "type" SELECT * FROM json_populate_record(NULL::"type", _a);
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>Table <code>name</code> is created using:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS "name" (
    "id"    TEXT NOT NULL,
    "value" TEXT NOT NULL,
    PRIMARY KEY ("id"),
    CHECK ("id"&lt;&gt;'' AND "value"&lt;&gt;'')
  );
  CREATE INDEX IF NOT EXISTS "idx_name_value"
  ON "name" ("value");
  
  
  CREATE OR REPLACE FUNCTION "name_insertone" (
    IN _a JSON
  ) RETURNS VOID AS $$
  BEGIN
    INSERT INTO "name" SELECT * FROM json_populate_record(NULL::"name", _a);
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>When is call <code>type_insertone()</code> with <code>{id: 'x', 'value': 'x'}</code>, it works.
  But when i do the same with <code>name_insertone()</code> it doesnt work!</p>
  
  <p>I was thinking if it could be possible that the function is created before the table is created, which could be causing it to not know the table <code>name</code>, but that i think is not the case.</p>
  
  <p>I dont know what should i try here. I have also checked that <code>name</code> is not a reserved keyword and so is <code>type</code>.</p>