Obtains the last serial number, used in a table.

1 sqlca.serial

<sqlca.serial />
Example

Recuperation of serial before a simple operation of INSERT.

Copy
<insert table='cenllote'>
    <column name='loteid'>0</column>        <!-- For Postgres not especify the serial column ! -->
    <column name='procname'>ccomfach</column>
    <column name='tabname'>ccomfach</column>
    <column name='colname'>facidx</column>
    <column name='modcon'>2</column>
</insert>
<set name='ccon_interfase_loteid'><sqlca.serial /></set>

It is stored in the variable called ccon_interfase_loteid, the serial value of the last register inserted in the table cenllote.

To increment the portability betwwen differents database managers, in special for Postgres, you should not explicit the column of serial type in the list of columns of the insert operation, it means, not to relate: <column name='loteid' >0 </column>.

Example

Recuperation of serial in combinated operations INSERT / SELECT: All engines except Postgres.

Copy
<table name='testser' >
    <column name='apteid' type='serial' required='y' />
    <column name='nom'    type='char' size='100' required='y' />

    <primary name='p_testser' columns='apteid' />
</table>
<set name='p_sqlcond'>%</set>

<!-- All engines, except Postgres -->
<insert table='testser' columns='apteid, nom'>
    <select>
        <columns>
            0 cabid, nomdia
        </columns>
    <from table='cdiarios'/>
    <where>
        cdiarios.codigo LIKE <p_sqlcond />
    </where>
    </select>
</insert>
<set name='m_apteid'><sqlca.serial /></set>

The serial content will just rescue if the insertion operation has generated a single register. If the operation has inserted more of one register it will generate the message:

WARNING: insert from select has returned more than one row, serial not returned.

Example

Recuperation of serial in combined operations INSERT / SELECT: Only engine Postgres.

Copy
<table name='testser' >
   <column name='apteid' type='serial' required='y' />
   <column name='nom'    type='char' size='100' required='y' />

   <primary name='p_testser' columns='apteid' />

</table>
<set name='p_sqlcond'>%</set>

<!-- Only engine Postgres: Not reporting serial column in tag columns and not returning sqlca.serial !  -->
<insert table='testser' columns='nom'>


   <select>
       <columns>
           namday
       </columns>
   <from table='cdiary'/>
   <where>
       cdiary.code LIKE <p_sqlcond />
   </where>
   </select>

</insert>


<set name='m_apteid'><sqlca.serial /></set>

The combined operations insert/select with Postgres database managers does not supports the value return of the serial content. It will show the message:

WARNING: insert from select can't return serial in POSTGRES engines.

In this case, the function sqlca.serial will return value zero.

In the combined operations insert/select with Postgres database managers, the serial column in the list of columns must not be informed. Note that in the example, the column apteid has been omitted in the tags columns