Skip to main content
Skip to main content

filesystem Table Function

Not supported in ClickHouse Cloud

Recursively iterates a directory and returns a table with file metadata (paths, sizes, types, permissions, modification times) and, optionally, file contents.

In clickhouse-server mode, the path must be within the user_files_path directory. Symlinks inside user_files_path that point outside of it are followed, but only entries whose path (through the symlink) starts with user_files_path are returned.

In clickhouse-local mode, there are no path restrictions.

Syntax

filesystem([path])

Arguments

ParameterDescription
pathThe directory to list. Can be an absolute path (must be inside user_files_path in server mode) or a path relative to user_files_path. If empty or omitted, defaults to user_files_path.

Returned columns

ColumnTypeDescription
pathStringDirectory containing the entry (does not include the file/directory name itself).
nameStringFile or directory name (the last component of the path).
fileString (ALIAS of name)Alias for the name column.
typeEnum8File type: 'none', 'not_found', 'regular', 'directory', 'symlink', 'block', 'character', 'fifo', 'socket', 'unknown'.
sizeNullable(UInt64)File size in bytes (for regular files). NULL for non-regular files (directories, symlinks, etc.) and on error.
depthUInt16Recursion depth. 0 for the queried directory itself and its immediate children, 1 for entries one level deeper, and so on.
modification_timeNullable(DateTime64(6))Last modification time with microsecond precision. NULL on error.
is_symlinkBoolWhether the entry is a symbolic link.
contentNullable(String)File contents (for regular files). NULL for non-regular files (directories, symlinks, etc.). Read errors raise an exception. Reading this column triggers actual file I/O, so omit it if not needed.
owner_readBoolOwner has read permission.
owner_writeBoolOwner has write permission.
owner_execBoolOwner has execute permission.
group_readBoolGroup has read permission.
group_writeBoolGroup has write permission.
group_execBoolGroup has execute permission.
others_readBoolOthers have read permission.
others_writeBoolOthers have write permission.
others_execBoolOthers have execute permission.
set_gidBoolSet-GID bit.
set_uidBoolSet-UID bit.
sticky_bitBoolSticky bit.

Only columns actually used in the query are computed, so selecting a subset of columns (especially omitting content) is efficient.

Examples

List files in user_files

SELECT name, type, size, depth
FROM filesystem()
ORDER BY name;

Find large files

SELECT path, name, size
FROM filesystem()
WHERE type = 'regular' AND size > 1000000
ORDER BY size DESC;

Read file contents

SELECT name, content
FROM filesystem('my_directory')
WHERE name LIKE '%.csv';

List only immediate children

SELECT name, type
FROM filesystem('my_directory')
WHERE depth = 0;