Categories:

Data metric functions

TABLE_SIZE_BYTES (system data metric function)

Returns the logical size, in bytes, of the associated table. The value is the same as the BYTES column of the TABLES view in the Information Schema.

Syntax

Not applicable.

Returns

The function returns a scalar value with a NUMBER data type.

Values larger than 9007199254740991 bytes (253 − 1, about 9 PB) are returned as 9007199254740991.

Usage notes

  • You can’t call this function directly. To learn how to associate the function with a table so it runs at regular intervals, see Associate a DMF.
  • This function is supported only for table objects. It can’t be associated with a view, materialized view, dynamic table, event table, or Apache Iceberg™ table. When you associate it with a schema, it applies only to tables in the schema.
  • You can’t use FILTER or WITHIN GROUP with this function.
  • To count the rows in a table rather than measure its size, use ROW_COUNT.

Example

Associate the function with the events table, and define an expectation that is violated when the table reaches 1 TB:

ALTER TABLE logs.public.events
  ADD DATA METRIC FUNCTION SNOWFLAKE.CORE.TABLE_SIZE_BYTES
    ON ()
    EXPECTATION under_1_tb (VALUE < 1000000000000);