FirebirdSQL logo

MAKE_DBKEY()

Creates a DBKEY value

Result type

BINARY(8)

Syntax
MAKE_DBKEY (relation, recnum [, dpnum [, ppnum]])
Table 1. RDB$GET_TRANSACTION_CN Function Parameters
Parameter Description

relation

Relation name or relation id

recnum

Record number.Either absolute (if dpnum and ppnum are absent), or relative (if dpnum present)

dpnum

Data page number.Either absolute (if ppnum is absent) or relative (if ppnum present)

ppnum

Pointer page number.

MAKE_DBKEY creates a DBKEY value using a relation name or ID, record number, and (optionally) logical numbers of data page and pointer page.

Note
  1. If relation is a string expression or literal, then it is treated as a relation name, and the engine searches for the corresponding relation ID.The search is case-sensitive.In the case of string literal, relation ID is evaluated at query preparation time.In the case of expression, relation ID is evaluated at execution time.If the relation cannot be found, then error isc_relnotdef is raised.

  2. If relation is a numeric expression or literal, then it is treated as a relation ID and used “as is”, without verification against existing relations.If the argument value is negative or greater than the maximum allowed relation ID (65535 currently), then NULL is returned.

  3. Argument recnum represents an absolute record number in the relation (if the next arguments dpnum and ppnum are missing), or a record number relative to the first record, specified by the next arguments.

  4. Argument dpnum is a logical number of data page in the relation (if the next argument ppnum is missing), or number of data pages relative to the first data page addressed by the given ppnum.

  5. Argument ppnum is a logical number of pointer page in the relation.

  6. All numbers are zero-based.Maximum allowed value for dpnum and ppnum is 232 (4294967296).If dpnum is specified, then recnum can be negative.If dpnum is missing and recnum is negative, then NULL is returned.If ppnum is specified, then dpnum can be negative.If ppnum is missing and dpnum is negative, then NULL is returned.

  7. If any of specified arguments is NULL, the result is also NULL.

  8. Argument relation is described as INTEGER during query preparation, but it can be overridden by a client application as VARCHAR or CHAR.Arguments recnum, dpnum and ppnum are described as BIGINT.

Examples of MAKE_DBKEY

  1. Select record using relation name (note that relation name is uppercase)

    select *
    from rdb$relations
    where rdb$db_key = make_dbkey('RDB$RELATIONS', 0)
  2. Select record using relation ID

    select *
    from rdb$relations
    where rdb$db_key = make_dbkey(6, 0)
  3. Select all records physically residing on the first data page

    select *
    from rdb$relations
    where rdb$db_key >= make_dbkey(6, 0, 0)
    and rdb$db_key < make_dbkey(6, 0, 1)
  4. Select all records physically residing on the first data page of 6th pointer page

    select *
    from SOMETABLE
    where rdb$db_key >= make_dbkey('SOMETABLE', 0, 0, 5)
    and rdb$db_key < make_dbkey('SOMETABLE', 0, 1, 5)