Project

General

Profile

« Previous | Next » 

Revision 10989

schemas/util.sql: offset2row_num(), limit2row_num(): added optional min_row_num, for tables whose serial pkeys start from a value other than 1

View differences:

schemas/util.sql
1207 1207

  
1208 1208

  
1209 1209
--
1210
-- Name: limit2row_num(integer, integer); Type: FUNCTION; Schema: util; Owner: -
1210
-- Name: limit2row_num(integer, integer, integer); Type: FUNCTION; Schema: util; Owner: -
1211 1211
--
1212 1212

  
1213
CREATE FUNCTION limit2row_num(limit_ integer, offset_ integer DEFAULT NULL::integer) RETURNS integer
1213
CREATE FUNCTION limit2row_num(limit_ integer, offset_ integer DEFAULT NULL::integer, min_row_num integer DEFAULT 1) RETURNS integer
1214 1214
    LANGUAGE sql IMMUTABLE
1215 1215
    AS $_$
1216
SELECT COALESCE(util.offset2row_num($2) + $1 - 1, 2147483647)
1216
SELECT COALESCE(util.offset2row_num($2, $3) + $1 - 1, 2147483647)
1217 1217
$_$;
1218 1218

  
1219 1219

  
......
1472 1472

  
1473 1473

  
1474 1474
--
1475
-- Name: offset2row_num(integer); Type: FUNCTION; Schema: util; Owner: -
1475
-- Name: offset2row_num(integer, integer); Type: FUNCTION; Schema: util; Owner: -
1476 1476
--
1477 1477

  
1478
CREATE FUNCTION offset2row_num(offset_ integer) RETURNS integer
1478
CREATE FUNCTION offset2row_num(offset_ integer, min_row_num integer DEFAULT 1) RETURNS integer
1479 1479
    LANGUAGE sql IMMUTABLE
1480 1480
    AS $_$
1481
SELECT COALESCE($1, 0)+1
1481
SELECT $2 + COALESCE($1, 0)
1482 1482
$_$;
1483 1483

  
1484 1484

  

Also available in: Unified diff