find_free_id
Scans a table's numeric id column up to a set range and returns the lowest unused value, so a new row can be inserted without a database sequence.
Instructions
Find a free id for a new row: scans 1..maxRange (default 1000, capped at 10000) and returns the lowest value not already used, so a key can be inserted without a sequence.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name. | |
| column | Yes | Numeric id column to search for a free value. | |
| schema | No | Schema (owner) of the table. Optional — defaults to the server's current schema; omit rather than guess. | |
| maxRange | No | Inclusive upper bound of the search window. Defaults to 1000; capped at 10000. | |
| excludeTable | No | Optional second table (same schema, same column) whose ids must also be avoided. |