Duplicate Inserted Row into the new table when running trigger I create 2 tables like this:

CREATE TABLE task
(
 task_name TEXT NOT NULL,
 duration INT,
 UNIQUE(task_name)
);
CREATE TABLE temptable
(
 task_name TEXT NOT NULL,
 duration INT  NULL,

);


Then I insert one row in 'task' table. 

INSERT INTO public.task(
    task_name, duration)
    VALUES ('task1', 10);


I want to insert a new same row into temptable table every time I add new record into task table
So I create a trigger to insert automatically data in 'temptale' at the same time

CREATE OR REPLACE FUNCTION update_temptable()
RETURNS TRIGGER AS
$$
BEGIN
    -- insert temporary row
    INSERT INTO temptable(task_name, duration)
    SELECT NEW.task_name , NEW.duration FROM task;
   RETURN NEW;       
END
$$
LANGUAGE 'plpgsql';
/* Create trigger call function*/
CREATE TRIGGER ins_new_record
    AFTER INSERT ON task
    FOR EACH ROW
    EXECUTE PROCEDURE update_temptable();


But when I insert a new row ('task 2',10) into 'task' table, the records inserted into 'temptable' table always duplicated like this.

task_name|duration|
|"task2" |10      |
-------------------

|"task2" |10      |


I don't know how to fix it. Can anyone help me? Thanks.
The statement in your trigger:

INSERT INTO temptable
   (task_name, duration)
SELECT NEW.task_name , NEW.duration
FROM task;


will insert as many rows into temptable as there are currently in task. The SELECT returns one result row for each row in task, and since the SELECT list contains only constants, all these result rows will look the same.

You want to insert a single row, so you should use

INSERT INTO temptable
   (task_name, duration)
VALUES (NEW.task_name , NEW.duration);