Related to my question here (postgres nonversioned editing - sequence vs next_rowid ) on returning the next_rowid for non-versioned Postgres database (Postgres 10.6/PostGIS 2.2), I'm trying to implement the next_row id (Next_RowID—Help | ArcGIS Desktop ) with an insert trigger, however I'm buffaloed on how to get this done. Hoping someone has done this before.
When I run a basic next_rowid select in PgAdmin, I get response I'm looking for (where 'data' is the schema and 'newtest_point2' is the table)
SQL:
<SPAN class="keyword token">select</SPAN> sde<SPAN class="punctuation token">.</SPAN>next_rowid<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'data'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'newtest_point2'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
Return: 481
Postgres documentation (Creating PostgreSQL Trigger Example )
Function:
<SPAN class="keyword token">CREATE</SPAN> <SPAN class="operator token">OR</SPAN> REPLACE <SPAN class="keyword token">FUNCTION</SPAN> test_trigger_func<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">RETURNS</SPAN> <SPAN class="keyword token">trigger</SPAN> <SPAN class="keyword token">AS</SPAN>
$BODY$
<SPAN class="keyword token">BEGIN</SPAN>
<SPAN class="comment token">#insert into data.newtest_point2 (objectid)</SPAN>
<SPAN class="comment token">#Values (sde.next_rowid('data', 'newtest_point2'));</SPAN>
new<SPAN class="punctuation token">.</SPAN>objectid<SPAN class="operator token">=</SPAN> sde<SPAN class="punctuation token">.</SPAN>next_rowid<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'data'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'newtest_point2'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">RETURN</SPAN> NEW<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">END</SPAN><SPAN class="punctuation token">;</SPAN>
$BODY$
LANGUAGE plpgsql<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Trigger:
<SPAN class="keyword token">CREATE</SPAN> <SPAN class="keyword token">TRIGGER</SPAN> test_trigger
BEFORE <SPAN class="keyword token">Insert</SPAN>
<SPAN class="keyword token">ON</SPAN> newtest_point2
<SPAN class="keyword token">FOR EACH ROW</SPAN>
<SPAN class="keyword token">EXECUTE</SPAN> <SPAN class="keyword token">PROCEDURE</SPAN> test_trigger_func<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>However my error (when adding creating points in ArcPro) :
Anyone have any suggestions or run into this before with implementing a insert trigger on next_rowid?
Note - I thought modifying back the trigger to "update" rather than "insert" did the trick, but it only appeared to work with an existing sequence.