so i harcoded my primary key in ows_storage.c <br>function ows_storage_fill_pkey() look like this :<br><br>static void ows_storage_fill_pkey(ows * o, ows_layer * l)<br>{<br>    buffer *sql;<br>    PGresult *res;<br><br>    assert(o);<br>
    assert(l);<br>    assert(l-&gt;storage);<br><br>    sql = buffer_init();<br><br>    buffer_add_str(sql, &quot;SELECT c.column_name FROM information_schema.constraint_column_usage c, pg_namespace n &quot;);<br>    buffer_add_str(sql, &quot;WHERE n.nspname = &#39;&quot;);<br>
    buffer_copy(sql, l-&gt;storage-&gt;schema);<br>    buffer_add_str(sql, &quot;&#39; AND c.table_name = &#39;&quot;);<br>    buffer_copy(sql, l-&gt;storage-&gt;table);<br>    buffer_add_str(sql, &quot;&#39; AND c.constraint_name = (&quot;);<br>
<br>    buffer_add_str(sql, &quot;SELECT c.conname FROM pg_class r, pg_constraint c, pg_namespace n &quot;);<br>    buffer_add_str(sql, &quot;WHERE r.oid = c.conrelid AND relname = &#39;&quot;);<br>    buffer_copy(sql, l-&gt;storage-&gt;table);<br>
    buffer_add_str(sql, &quot;&#39; AND r.relnamespace = n.oid AND n.nspname = &#39;&quot;);<br>    buffer_copy(sql, l-&gt;storage-&gt;schema);<br>    buffer_add_str(sql, &quot;&#39; AND c.contype = &#39;p&#39;)&quot;);<br>
<br>    res = ows_psql_exec(o, sql-&gt;buf);<br>    /*----------------------ENLEVER------------------*/<br>   /* if (PQresultStatus(res) != PGRES_TUPLES_OK) {<br>        PQclear(res);<br>        buffer_free(sql);<br>        ows_error(o, OWS_ERROR_REQUEST_SQL_FAILED, &quot;Unable to access pg_* tables.&quot;, &quot;pkey column&quot;);<br>
        return;<br>    }*/<br><br>    /* Layer could have no Pkey indeed... (An SQL view for example) */<br>    /* if (PQntuples(res) == 1) {*/<br>        l-&gt;storage-&gt;pkey = buffer_init();<br>        /*----------ENLEVER-------------*/<br>
       /* buffer_add_str(l-&gt;storage-&gt;pkey, PQgetvalue(res, 0, 0));*/<br>        buffer_add_str(l-&gt;storage-&gt;pkey, &quot;ogc_fid&quot;);<br>        buffer_empty(sql);<br>        PQclear(res);<br><br>        /* Retrieve the Pkey column number */<br>
        buffer_add_str(sql, &quot;SELECT a.attnum FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n&quot;);<br>        buffer_add_str(sql, &quot; WHERE a.attnum &gt; 0 AND a.attrelid = c.oid AND a.atttypid = t.oid AND n.nspname=&#39;&quot;);<br>
        buffer_copy(sql, l-&gt;storage-&gt;schema);<br>        buffer_add_str(sql, &quot;&#39; AND c.relname=&#39;&quot;);<br><br>        buffer_copy(sql, l-&gt;storage-&gt;table);<br>        buffer_add_str(sql, &quot;&#39; AND a.attname=&#39;ogc_fid&#39;&quot;);<br>
<br>        /* buffer_copy(sql, l-&gt;storage-&gt;pkey);<br>        buffer_add_str(sql, &quot;&#39;&quot;);*/<br>        res = ows_psql_exec(o, sql-&gt;buf);<br>        if (PQresultStatus(res) != PGRES_TUPLES_OK) {<br>            PQclear(res);<br>
            buffer_free(sql);<br>            ows_error(o, OWS_ERROR_REQUEST_SQL_FAILED, &quot;Unable to find pkey column number.&quot;, &quot;pkey_column number&quot;);<br>            return;<br>        }<br><br>        /* -1 because column number start at 1 */<br>
        l-&gt;storage-&gt;pkey_column_number = atoi(PQgetvalue(res, 0, 0)) - 1;<br>        buffer_empty(sql);<br>        PQclear(res);<br><br>        /* Now try to find a sequence related to this Pkey<br>        buffer_add_str(sql, &quot;SELECT pg_get_serial_sequence(&#39;&quot;);<br>
        buffer_copy(sql, l-&gt;storage-&gt;schema);<br>        buffer_add_str(sql, &quot;.\&quot;&quot;);<br>        buffer_copy(sql, l-&gt;storage-&gt;table);<br>        buffer_add_str(sql, &quot;\&quot;&#39;, &#39;&quot;);<br>
        buffer_copy(sql, l-&gt;storage-&gt;pkey);<br>        buffer_add_str(sql, &quot;&#39;);&quot;);<br>        */<br><br>        /*NEW function in PG*/<br>        buffer_add_str(sql, &quot;SELECT get_sequence_view(&#39;&quot;);<br>
        buffer_copy(sql, l-&gt;storage-&gt;table);<br>        buffer_add_str(sql, &quot;&#39;);&quot;);<br><br>        res = ows_psql_exec(o, sql-&gt;buf);<br>        if (PQresultStatus(res) != PGRES_TUPLES_OK) {<br>            PQclear(res);<br>
            buffer_free(sql);<br>            ows_error(o, OWS_ERROR_REQUEST_SQL_FAILED,<br>                  &quot;Unable to use pg_get_serial_sequence.&quot;, &quot;pkey_sequence retrieve&quot;);<br>            return;<br>
        }<br><br>        /* Even if no sequence found, this function return an empty row<br>         * so we must check that result string returned &gt; 0 char<br>         */<br>        if (PQntuples(res) == 1 &amp;&amp; strlen((char *) PQgetvalue(res, 0, 0)) &gt; 0) {<br>
            l-&gt;storage-&gt;pkey_sequence = buffer_init();<br>            buffer_add_str(l-&gt;storage-&gt;pkey_sequence, PQgetvalue(res, 0, 0));<br>        }<br>/*    }*/<br><br>    PQclear(res);<br>    buffer_free(sql);<br>
}<br><br><br>and get_sequence_view() looks like :<br><br>CREATE OR REPLACE FUNCTION get_sequence_view(name_table character varying)<br>  RETURNS text AS<br>$BODY$<br><br>DECLARE<br>   <br>    viewn varchar;<br>    resultat varchar := &#39;&#39;;<br>
    nom_seq varchar;<br>    current_seq integer;<br>    <br>BEGIN<br><br>    viewn := name_table;<br>     <br>    SELECT table_name FROM information_schema.view_table_usage where view_name = viewn into resultat;<br>    <br>
    /* if resultat &lt;&gt; &quot;&quot; so view else it&#39;s a table */<br><br>    if (resultat &lt;&gt; &#39;&#39;) then<br>        SELECT pg_get_serial_sequence(resultat,&#39;ogc_fid&#39;)::text into nom_seq;<br>        --SELECT currval(nom_seq) into current_seq;<br>
    ELSE<br>        SELECT pg_get_serial_sequence(viewn,&#39;ogc_fid&#39;)::text into nom_seq;<br>        --SELECT currval(nom_seq) into current_seq;<br>    END IF;<br><br>    RETURN nom_seq;<br>  <br>END<br>$BODY$<br>  LANGUAGE plpgsql VOLATILE<br>
  COST 100;<br><br><br>very personalized but it works when <br>1- table got primary key : ogc_fid<br>2- view content ogc_fid<br>3- view got just one table<br>4- view with rules on INSERT, DELETE, UPDATE<br>