Create a function to insert columns from one table to another in PostgreSQL
<p>I have GPS Data that gets stored in the default storage of GPS PLUS X from Vectronic. In GPS PLUS X I can copy that my PostgreSQL Database (stored in the table public.gps_plus_positions). From this table I would like to extract certain columns with a function and automatically insert into another table, every time the public.gps_plus_positions gets updated.</p>

<p>Therefore I run the following code (for the simple case of just one column to extract): </p>

<pre><code>CREATE TABLE main.gps_test(
utc_date date)

CREATE OR REPLACE FUNCTION tools.gps_plus_positions2gps_test()
RETURNS trigger AS
$BODY$ begin
INSERT INTO main.gps_test(utc_date)
 SELECT 
    NEW.utc_date
;
RETURN NULL;
END
$BODY$
LANGUAGE plpgsql VOLATILE;
COMMENT ON FUNCTION tools.gps_plus_positions2gps_test()
IS 'Automatic upload data from gps_data to gps_test.';

CREATE TRIGGER trigger_gps_data_upload2test
  AFTER INSERT
  ON public.gps_plus_positions
  FOR EACH ROW
  EXECUTE PROCEDURE tools.gps_plus_positions2gps_test();
COMMENT ON TRIGGER trigger_gps_data_upload2test ON public.gps_plus_positions
IS 'Automatic upload data from gps_plus positions to gps_test.';
</code></pre>

<p>But as soon as I run that code, copying the data from the default storage in GPS PLUS X to the PostgreSQL module is not executed anymore. Hence I suppose there is an error in my code.</p>

<p>I'd be very grateful about any suggestions to fix this problem.</p>

<p>Cheers!</p>