title: SQL Query error insert into
body: <p>I'm trying to do this function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION "SA_PRJ".usp_verify_allocated_time(p_uid integer, p_project_id integer,   p_allocated_time numeric, p_achieved_time numeric, p_task_desc character varying, p_obs character  varying, p_date timestamp without time zone)
  RETURNS void AS
  
  $BODY$
  declare alloc_id integer;
  
  BEGIN
     if not "SA_ADM".usp_check_permission(p_uid, 'SA_PRJ', 'usp_add_timesheet_record') then
      raise exception 'User ID % nu are permisii pentru aceasta operatie!', p_uid;
     end if;
  SELECT *,
     case when SUM(fld_allocated_time) / 24 &lt; fld_allocated_days 
  then 
     INSERT INTO "SD_PRJ".tbl_project_timesheet(fld_emp_id, fld_project_id,        fld_is_allocated,fld_allocated_time, fld_achieved_time,    fld_task_desc, fld_obs)
      VALUES (p_uid,p_project_id,coalesce(alloc_id,0), p_allocated_time, p_achieved_time,p_task_desc, p_obs);
  
  else 'Not OK' 
  end as Alocated
  from
  (
    SELECT p.fld_id, p.fld_allocated_days, t.fld_allocated_time
    FROM "SD_PRJ".tbl_project p
    INNER JOIN "SD_PRJ".tbl_project_timesheet t
    ON p.fld_id=t.fld_id
    where t.fld_project_id = p_project_id
  )AS Alias
  GROUP BY fld_id, fld_allocated_days, fld_allocated_time
  END;
  
  $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
  ALTER FUNCTION "SA_PRJ".usp_usp_verify_allocated_time(integer, integer, numeric, numeric, character varying,   character varying, timestamp without time zone)
  OWNER TO postgres;
  </code></pre>
  
  <p>I want to make a function to join two columns from tables <code>"SD_PRJ".tbl_project</code> and   <code>"SD_PRJ".tbl_project_timesheet</code> and make the compare <code>SUM(fld_allocated_time) / 24 &lt; fld_allocated_days</code>
  from an input parameter <code>p_project_id (WHERE t.fld_project_id = p_project_id)</code> and make the insert if its ok or not.</p>
  
  <p>The input column fld_project_id can have more than 1 appear in the table.</p>
  
  <pre><code>tbl_ = table name
  fld_ = column / field name
  
  "SD_PRJ" = my schema name
  \ERROR:  syntax error at or near "INTO"
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>LINE 12:    INSERT INTO "SD_PRJ".tbl_project_timesheet(fld_emp_id, fl...
                   ^</p>
    
    <p>********** Error **********</p>
    
    <p>ERROR: syntax error at or near "INTO" SQL state: 42601 Character: 550</p>
  </blockquote>