title: Populate fields x,y or long, lat, depending on input data, and create a point based on input
body: <p>I have a table created as follows:</p>
  
  <pre><code>CREATE TABLE public."EESsite" (
     "ID" integer NOT NULL,
     "Name" character varying(254),
     "LatitudeDe" double precision,
     "Longitud_1" double precision,
     "Easting" double precision,
     "Northing" double precision,
     geom geometry(Point,32636),
      CONSTRAINT "PrimaryKey" PRIMARY KEY ("ID"))
        WITH (
        OIDS=FALSE
        );
  ALTER TABLE public."EESsite"
  </code></pre>
  
  <p>What I want to do is to populate either Longitud_1,LatitudeDE, or Easting ,Northing, depending on the input data. For example, sometimes I have teh coordinates in LonLat format, but sometimes I have them is UTM, but I need both in my columns. From each pair of coordinates I want to create a point using a function and a trigger. I have been able to produce the point automatically and extract the coordinates from geom to put them into the columns, but I have not been able to  do it programmatically. I have tried this:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION update_latlon_column() 
    RETURNS TRIGGER AS
    $BODY$
     BEGIN
      IF NEW."Longitud_1" IS NULL THEN
      NEW.geom =(ST_Transform(ST_SetSRID(ST_MakePoint(NEW."Longitud_1"::float8,NEW."LatitudeDe"::float8),4326),32636));
      end if;
      IF NEW."Easting" IS NULL THEN
      NEW.geom = ST_SetSRID(ST_MakePoint(NEW."Easting"::float8, NEW."Northing"::float8), 32636),
      NEW.Longitud_1 = (ST_SetSRID(ST_Y(geom),32636),4326),
      NEW.LatitudeDe = (ST_SetSRID(ST_X(geom),32636),4326);
      end if;
     RETURN new;
     END;
    $BODY$
   language plpgsql;
  
  
   CREATE TRIGGER update_geom
      BEFORE INSERT OR UPDATE
      ON public."EESsite"
      FOR EACH ROW
      EXECUTE PROCEDURE  update_latlon_column();
  </code></pre>
  
  <p>I can create both the function and the trigger, but whenever I try to add a new row I run into this problem:</p>
  
  <blockquote>
    <p>ERROR: record "new" has no field "longitud_1"</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/puipo.png" rel="nofollow noreferrer"></a></p>
  
  <p>Any help would be very appreciated.</p>
  
  <p>Thank you</p>