<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Postgresql trigger to maintain coloumn uniqueness in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672633#M12073</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, I don't do much with Field Maps, and have nothing else to offer here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 12 Dec 2025 14:39:20 GMT</pubDate>
    <dc:creator>JeffSilberberg</dc:creator>
    <dc:date>2025-12-12T14:39:20Z</dc:date>
    <item>
      <title>Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1669289#M12008</link>
      <description>&lt;P&gt;I am writing a trigger in Postgresql database so that one particular coloumn can maintain its uniqueness.&lt;/P&gt;&lt;P&gt;The idea is to check the data before they are entered. The data are entered via Field Map.&lt;/P&gt;&lt;P&gt;So, I write a Function below :&lt;/P&gt;&lt;P&gt;CREATE OR REPLACE FUNCTION xxx_check_unique()&lt;BR /&gt;RETURNS TRIGGER&lt;BR /&gt;AS&lt;BR /&gt;$$&lt;BR /&gt;BEGIN&lt;BR /&gt;&amp;nbsp;IF (SELECT EXISTS(SELECT FROM scema1.chamber where id = new.id)) = 'false' THEN&lt;BR /&gt;&amp;nbsp; &amp;nbsp;RETURN new;&amp;nbsp; &amp;nbsp;//entry the new record&lt;BR /&gt;&amp;nbsp; &amp;nbsp;else&lt;BR /&gt;&amp;nbsp; &amp;nbsp;RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'DUP';&lt;BR /&gt;&amp;nbsp; &amp;nbsp;return null;&amp;nbsp; &amp;nbsp;//do not entry due to duplication&lt;BR /&gt;&amp;nbsp;end if;&lt;BR /&gt;END;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;CREATE OR REPLACE TRIGGER xx_check_unique&lt;BR /&gt;BEFORE update of id ON scema1.chamber&lt;BR /&gt;FOR EACH ROW EXECUTE PROCEDURE xxx_check_unique();&lt;/P&gt;&lt;P&gt;CREATE OR REPLACE TRIGGER xx_check_unique&lt;BR /&gt;BEFORE insert ON scema1.chamber&lt;BR /&gt;FOR EACH ROW EXECUTE PROCEDURE xxx_check_unique();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That trigger works using Field Map if I enter an ID that's never been entered before.&lt;/P&gt;&lt;P&gt;If the ID entered has existed in the record, then an error comes up :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yockee_0-1764573555301.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/144581iB07FFAA615B73229/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yockee_0-1764573555301.png" alt="yockee_0-1764573555301.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then, if I want to entry another data, *i have to repeat the process from the very beginning, with all empty coloumns*. I f I just change the ID into another unique ID, the same error message comes up just like the picture above.&lt;/P&gt;&lt;P&gt;So, how can I employ such a trigger.&lt;/P&gt;&lt;P&gt;FYI, this trigger works in Desktop without error.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 07:24:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1669289#M12008</guid>
      <dc:creator>yockee</dc:creator>
      <dc:date>2025-12-01T07:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1669335#M12010</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/116349"&gt;@yockee&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are these IDs bound by any certain restriction? Be it like a GUID&amp;nbsp; or similar? When a feature is inserted, you could have a calculated field on Field Maps create a GUID using the GUID() function, or something like&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;return count($layer) + 1;&lt;/PRE&gt;&lt;P&gt;That would return a much different ID but still something unique, what are your restrictions currently?&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Mon, 01 Dec 2025 14:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1669335#M12010</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2025-12-01T14:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1669523#M12013</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/712076"&gt;@CodyPatterson&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;The only restriction is that it has to be unique. This ID is based on another layer underneath it (the ID of the layer underneath is already unique) and the data have to be entered manually. I have to run this mechanism of entering it manually because I have to do so : the layer underneath is a polyline, whereas the one that I am working is a point layer. One of the points inside a polyline must have the ID of that polyline.&lt;/P&gt;&lt;P&gt;The trigger above somehow actually works in Field Map not in a way it is intended. If I enter an ID that is already existed and filled in all other text boxes (there are around 12 questionaires), press SUBMIT, and then that error (that error in the pic above) comes up. After the error, I just *can not simply change* the ID to another unique&amp;nbsp; value and then press SUBMIT again. The same error comes up.&lt;/P&gt;&lt;P&gt;But, if I do the entry from the beginning (with all 12 text boxes emptied out), and put in a unique ID, it will work without error. This is pains as I have to fill in all the text boxes again.&lt;/P&gt;&lt;P&gt;I have overcome this problem of re-entering-data-from-beginning by employing Attribute Validation, set in Arcgis Pro, below. But this method is rather process heavy because all data are copied into Datastore. If only a few records this method will work fine.&lt;/P&gt;&lt;P&gt;(PS: I am curious, where does this validation is stored ? i presume in Arcgis Server )&lt;/P&gt;&lt;P&gt;:::&lt;BR /&gt;if (id == null || id == "") {&lt;BR /&gt;return true;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;var fs = FeatureSetByName(&lt;BR /&gt;$datastore,&lt;BR /&gt;"db_city.scema1.data1",&lt;BR /&gt;["oid_code ", "objectid"],&lt;BR /&gt;false&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;var oid_self = $feature.objectid;&lt;/P&gt;&lt;P&gt;var others = Filter(fs, "oid_code = @id AND objectid &amp;lt;&amp;gt; @oid_self");&lt;/P&gt;&lt;P&gt;if (Count(others) &amp;gt; 0) {&lt;BR /&gt;return {&lt;BR /&gt;"errorMessage": "id already existed"&lt;BR /&gt;};&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Dec 2025 00:48:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1669523#M12013</guid>
      <dc:creator>yockee</dc:creator>
      <dc:date>2025-12-02T00:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1670176#M12032</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/116349"&gt;@yockee&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I believe you will find that your PostgreSQL function is broken -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF (SELECT EXISTS(SELECT FROM scema1.chamber where id = new.id)) = 'false' THEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; Should probably be&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; IF NOT EXISTS (SELECT 1 FROM schema1.chamber WHERE id = NEW.id) THEN&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;As EXISTS returns a Bool, not a Text Value, which you have specified.&amp;nbsp; Also, your&amp;nbsp;RAISE EXCEPTION does not look correct, but maybe, it could just be a style thing.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Dec 2025 17:21:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1670176#M12032</guid>
      <dc:creator>JeffSilberberg</dc:creator>
      <dc:date>2025-12-03T17:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672209#M12063</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/140376"&gt;@JeffSilberberg&lt;/a&gt;&amp;nbsp;The code you provide gives out the same result.&lt;/P&gt;&lt;P&gt;Anyway, now I find out behaviour in Field Map this :&lt;/P&gt;&lt;P&gt;1. I enter duplicate value. press SUBMIT&lt;/P&gt;&lt;P&gt;2. Error comes up "Unable to submit. Service error code 500. bla bla"&lt;/P&gt;&lt;P&gt;3. Then without exiting, I edit the value again. Now type in a non-duplicate value. press SUBMIT again&lt;/P&gt;&lt;P&gt;4.&amp;nbsp;Error comes up "Unable to submit. Service error code 500. bla bla"&lt;/P&gt;&lt;P&gt;5. Then I press SUBMIT again straight away. Success.&amp;nbsp;&lt;/P&gt;&lt;P&gt;6. I check the database. The record is there with objectID x+3&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is, when I press SUBMIT for the second time (step #3), the record will be inserted without error.&lt;/P&gt;&lt;P&gt;The trigger itself is not a problem when executed using database query run from PGADMIN.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;FYI, Anyway, these 3 codes give out the same result in postgres:&lt;/P&gt;&lt;P&gt;1.&lt;SPAN&gt;IF (SELECT EXISTS(SELECT FROM scema1.chamber where id = new.id)) = 'false' THEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2.&lt;SPAN&gt;IF (SELECT EXISTS(SELECT 1 FROM scema1.chamber where id = new.id)) = 'false' THEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;3.&lt;SPAN&gt;IF NOT EXISTS (SELECT 1 FROM schema1.chamber WHERE id = NEW.id) THEN&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 03:00:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672209#M12063</guid>
      <dc:creator>yockee</dc:creator>
      <dc:date>2025-12-11T03:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672210#M12064</link>
      <description>&lt;P&gt;Use ChatGPT to check your logic and syntax. You have a number of issues here, including that you can not compare a Boolean to a String.&amp;nbsp;&lt;/P&gt;&lt;P&gt;but there are &lt;STRONG&gt;several PostgreSQL syntax issues&lt;/STRONG&gt;:&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;1. schema1 is spelled wrong (scema1)&lt;/STRONG&gt;&lt;/H3&gt;&lt;H3&gt;&lt;STRONG&gt;2. EXISTS(...) returns a boolean, not text&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;You should compare it to &lt;STRONG&gt;TRUE/FALSE&lt;/STRONG&gt;, not the string 'false'.&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;3. PostgreSQL does NOT use // for comments&lt;/STRONG&gt;&lt;/H3&gt;&lt;P&gt;Use -- or /* */.&lt;/P&gt;&lt;H3&gt;&lt;STRONG&gt;4. RETURN NULL is correct, but must come &lt;EM&gt;after&lt;/EM&gt; raising the exception (which already stops execution)&lt;/STRONG&gt;&lt;/H3&gt;&lt;H3&gt;&lt;STRONG&gt;5. Trigger functions must be in LANGUAGE plpgsql&lt;/STRONG&gt;&lt;/H3&gt;&lt;LI-CODE lang="sql"&gt;CREATE OR REPLACE FUNCTION xxx_check_unique()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
    -- If no record exists with the same ID, allow insert/update
    IF NOT EXISTS (SELECT 1 FROM schema1.chamber WHERE id = NEW.id) THEN
        RETURN NEW;  
    ELSE
        -- Raise custom error
        RAISE EXCEPTION SQLSTATE '90001'
            USING MESSAGE = 'DUP: id already exists in schema1.chamber';
        RETURN NULL; 
    END IF;
END;
$$;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 11 Dec 2025 03:39:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672210#M12064</guid>
      <dc:creator>JeffSilberberg</dc:creator>
      <dc:date>2025-12-11T03:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672216#M12065</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/140376"&gt;@JeffSilberberg&lt;/a&gt;&amp;nbsp;Yes..&amp;nbsp; shouldn't be "scema". I just want to show that the table reside in a schema. Thanks&lt;/P&gt;&lt;P&gt;Anyway, I did try the code you give me. Still the same behaviour on the Field Map, just like what I have described above.&lt;/P&gt;&lt;P&gt;The problem is not with the trigger, but how the Field Map reacts to the trigger.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Dec 2025 06:11:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672216#M12065</guid>
      <dc:creator>yockee</dc:creator>
      <dc:date>2025-12-11T06:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672603#M12070</link>
      <description>&lt;P&gt;Here are some results that I pulled from Arcgis Server Log:&lt;/P&gt;&lt;P&gt;===&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;else&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'DUP';&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;return null;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;SEVERE Dec 12, 2025, 14:36:02 An error occurred. /test_1.MapServer&lt;BR /&gt;SEVERE Dec 12, 2025, 14:36:02 Error: Underlying DBMS error [ERROR: 504 INSERT CONTEXT: PL/pgSQL function test() line 17 at RAISE (schema1.test_1)::SQLSTATE=P0001] [test_1]. Test01/test_1.MapServer&lt;/P&gt;&lt;P&gt;===&lt;SPAN&gt;else&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'DUP';&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;return 0;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;Error: Underlying DBMS error [ERROR: cannot return non-composite value from function returning composite type CONTEXT: PL/pgSQL function test() line 19 at RETURN (schema1.test_1)::SQLSTATE=42804] [test_1].&lt;/P&gt;&lt;P&gt;===&lt;SPAN&gt;else&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; RAISE EXCEPTION SQLSTATE '90001' USING MESSAGE = 'DUP'&lt;/SPAN&gt;&lt;SPAN&gt;;&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;Error: Underlying DBMS error [ERROR: control reached end of trigger procedure without RETURN CONTEXT: PL/pgSQL function test() (schema1.test_1)::SQLSTATE=2F005] [test_1].&lt;/P&gt;&lt;P&gt;===Without raise dan Without return&lt;BR /&gt;No error message&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Dec 2025 09:30:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672603#M12070</guid>
      <dc:creator>yockee</dc:creator>
      <dc:date>2025-12-12T09:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672633#M12073</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry, I don't do much with Field Maps, and have nothing else to offer here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Dec 2025 14:39:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1672633#M12073</guid>
      <dc:creator>JeffSilberberg</dc:creator>
      <dc:date>2025-12-12T14:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: Postgresql trigger to maintain coloumn uniqueness</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1679872#M12221</link>
      <description>&lt;P&gt;I come to a conclusion that somehow the Field Map can not handle such error in a correct manner.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Allow me to summarize the trouble after a trigger is implemented:&lt;/P&gt;&lt;P&gt;1. First, entry an *incorrect* record (data that has already existed)&lt;/P&gt;&lt;P&gt;2. The response from the Field Map : "Error.."&lt;/P&gt;&lt;P&gt;3. Second, entry a *correct* data.&lt;/P&gt;&lt;P&gt;4. The response from the Field Map : "Error.."&lt;/P&gt;&lt;P&gt;5. Repeat step 3 by directly hitting the Save button&lt;/P&gt;&lt;P&gt;6.&amp;nbsp;The response from the Field Map : "Success !"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, for my case above, the second entry (step number 3), the Field Map still regard it as error. The subsequent entry (step number 5), is success. The trigger is not a problem.&lt;/P&gt;&lt;P&gt;It seems that the Field Map still regard the second entry (step number 3) incorrect due to the first entry (step number 1). Perhaps there is a cache that has not been cleared. Or maybe something else.&lt;/P&gt;&lt;P&gt;I can not confirm the exact cause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jan 2026 03:19:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/postgresql-trigger-to-maintain-coloumn-uniqueness/m-p/1679872#M12221</guid>
      <dc:creator>yockee</dc:creator>
      <dc:date>2026-01-26T03:19:55Z</dc:date>
    </item>
  </channel>
</rss>

