 
 CREATE TABLE public.flat_abcd as 
 (
+  SELECT 
   nextval('public.flat_abcd_id_seq') as id,
   f.id as flat_ref,
   

    i.id as identification_ref,
    c.people_ref
  FROM
    darwin2.identifications_abdc i
    INNER JOIN darwin2.catalogue_people c on i.old_identification_id = c.record_id AND c.referenced_relation='identifications'
    INNER JOIN darwin2.people p on p.id = c.people_ref
  WHERE

    m.name as mineral_name,
    f.mineral_ref as mineral_ref,
    m.classification as classification
    FROM  public.identifications_abdc i
    INNER JOIN darwin2.darwin_flat  f on i.flat_id = f.id
    INNER JOIN darwin2.mineralogy m on f.mineral_ref = m.id
    WHERE i.is_current = true
