G.8. Reading Delta Datasets (delta_scan) #

Before reading Delta datasets, configure the Delta extension.

Required privileges: Superuser or the Postgres Pro AXE administrator.

For more information about access management, refer to Chapter 17.

Execute the following command on the Postgres Pro AXE server:

  SELECT * FROM delta_scan('path', optional_parameters);
  

Where:

  • path: The path to the Delta dataset that must be read.

  • optional_parameters: The optional parameters, specified in the parameter := value format.

    Available parameters:

    • delta_file_number: Specifies whether to return the delta_file_number column with the index of the physical Parquet file for each row.

      Possible values:

      • true

      • false

      Default value: false.

    • binary_as_string: Specifies whether to return binary columns as strings.

      Possible values:

      • true

      • false

      Default value: false.

    • filename: Specifies whether to return the filename column with file paths. Since DuckDB v1.3.0, this column is added automatically.

      Possible values:

      • true

      • false

      Default value: false.

    • file_row_number: Specifies whether to return the file_row_number column with row numbers of Parquet files.

      Possible values:

      • true

      • false

      Default value: false.

    • hive_partitioning: Specifies whether the directory is associated with a partitioned analytical table and whether partition columns are returned.

      Possible values:

      • true

      • false

      Default value: Detected automatically based on the directory structure.

      For more information about Hive partitioning, refer to Section 15.2.

    • hive_types: The data types of partition columns, specified as a STRUCT value.

      If the hive_types_autocast parameter is set to true, the DATE, TIMESTAMP, and BIGINT data types are detected automatically.

      Default value: ''.

      For more information about Hive partitioning, refer to Section 15.2.

    • hive_types_autocast: Specifies whether to detect the DATE, TIMESTAMP, and BIGINT data types of partition columns automatically.

      Possible values:

      • true

      • false

      You can specify data types of partition columns manually using the hive_types parameter.

      Default value: true.

    • union_by_name: Specifies whether columns from different files are aligned by name instead of by position.

      Possible values:

      • true

      • false

      If this parameter is set to true, memory consumption increases.

      Default value: false.

    • schema: The custom schema for reading Parquet files, specified as a MAP value.

Postgres Pro AXE will return rows of the Delta dataset.

Example G.10. Reading a Delta Dataset

  SELECT * FROM delta_scan('data/delta/dataset');
  
   id |  name   | age
  ----+---------+-----
    1 | Alice   |  30
    2 | Bob     |  25
    3 | Charlie |  35
  

You can select specific columns by assigning an alias to a procedure, such as r, and using the r['column_name'] syntax:

  SELECT r['id'], r['name'] FROM delta_scan('data/delta/dataset') r WHERE r['age'] = 25;
  
   id | name
  ----+------
  2 | Bob
  

FAQ