Skip to content

SQL API

The eleven silo_api functions, their arguments, permissions and limits.
Note

The public silo_api SQL interface is a Preview feature in the MVP release. Callers must connect with an ordinary application SQL role (never the installation owner) and execute write functions under Read Committed isolation.

The public SQL API consists of the 11 functions in the silo_api schema listed below. Functions and tables in the silo schema are private implementation internals and must not be called by applications.

Calling contract

  • Authorization checks session_user; SET ROLE is rejected. The installation owner (silo_owner) and its role members cannot call silo_api functions.
  • Callers need USAGE on silo_api, EXECUTE on each required function, and the corresponding table privileges on the bucket’s ACL relation in silo_bucket. Functions are not granted to PUBLIC. See Authorization.
  • Write functions require Read Committed (or PostgreSQL Read Uncommitted, which behaves identically). Calling write functions under Repeatable Read or Serializable raises SQLSTATE 0A000.
  • Object mutations and application table rows commit or roll back atomically in the same SQL transaction. Independent S3 HTTP requests do not join that transaction. Direct SQL writes do not emit S3 bucket event notifications.
  • Object keys are 1–1024 UTF-8 bytes; zero-length bytea bodies are valid. Passing SQL NULL for p_version_id targets the current version. To target an S3 null version explicitly, pass UUID '00000000-0000-0000-0000-000000000000' (not the string 'null').
  • Inline put_object, get_object, and copy_object bodies are capped at min(SILO_PG_MAX_OBJECT_SIZE, 256 MiB). read_object returns at most 8 MiB (8388608 bytes) per call.
  • SQL functions do not decrypt SSE-encrypted bodies or allow plaintext writes to bypass default bucket encryption. All SQL mutations obey synchronized bucket policies, hard bucket quotas, Object Lock retention, and legal holds, with no governance bypass parameter.

Object functions

put_object

silo_api.put_object(
  p_bucket text, p_key text, p_data bytea,
  p_content_type text DEFAULT 'application/octet-stream',
  p_user_meta jsonb DEFAULT '{}',
  p_if_none_match boolean DEFAULT false,
  p_if_match text DEFAULT NULL
)
RETURNS TABLE (
  object_id bigint, version_id uuid, etag text,
  size bigint, mod_time timestamptz
)

Requires INSERT on the destination bucket ACL relation. Setting p_if_none_match = true succeeds only when no current object body exists (a current delete marker does not block the write). p_if_match takes an unquoted ETag string, or '*' to require an existing current body. The two condition parameters are mutually exclusive and each additionally requires SELECT on the bucket. Conditions are evaluated atomically at publication.

p_user_meta must be a flat JSON object with string values (for example, '{"invoice-id":"1001"}'). Omit the x-amz-meta- prefix; the function normalizes keys and rejects reserved names, case-insensitive duplicates, CR/LF characters, and non-string values. Total normalized user metadata is capped at 2048 bytes, and p_content_type is capped at 1024 bytes without CR/LF.

stat_object

silo_api.stat_object(
  p_bucket text, p_key text, p_version_id uuid DEFAULT NULL
)
RETURNS TABLE (
  object_id bigint, version_id uuid,
  is_latest boolean, is_delete_marker boolean,
  size bigint, actual_size bigint, etag text, content_type text,
  user_meta jsonb, user_tags text, mod_time timestamptz,
  commit_seq bigint, encrypted boolean
)

Requires SELECT on the bucket. Returns metadata (including whether the selected version is a delete marker) without reading the object body or exposing private encryption keys. user_meta contains user metadata stripped of x-amz-meta- prefixes. size is the stored payload size and actual_size is the logical plaintext size.

get_object

silo_api.get_object(
  p_bucket text, p_key text, p_version_id uuid DEFAULT NULL
) RETURNS bytea

Requires SELECT on the bucket. Returns the complete plaintext body within the 256 MiB inline limit. Raises SO001 if the selected version is a delete marker or missing, and 0A000 if the object is encrypted.

read_object

silo_api.read_object(
  p_bucket text, p_key text,
  p_offset bigint DEFAULT 0, p_length bigint DEFAULT 8388608,
  p_version_id uuid DEFAULT NULL, p_object_id bigint DEFAULT NULL
)
RETURNS TABLE (
  object_id bigint, version_id uuid, offset_bytes bigint, data bytea
)

Requires SELECT on the bucket. p_offset must be >= 0 and not past the end of the object; p_length must be 0–8388608 (8 MiB). Reads crossing the end of the object are truncated. When p_object_id is non-NULL, the function verifies that the selected version still has that object_id and raises SO002 on mismatch. To keep multi-chunk reads consistent across statements, pin an immutable version_id or run inside a read-only Repeatable Read transaction.

list_objects

silo_api.list_objects(
  p_bucket text, p_prefix text DEFAULT '',
  p_after_key text DEFAULT NULL, p_limit integer DEFAULT 1000
)
RETURNS TABLE (
  object_id bigint, key text, version_id uuid, size bigint,
  etag text, content_type text, mod_time timestamptz, commit_seq bigint
)

Requires SELECT on the bucket. Lists current visible objects (excluding delete markers) ordered by key COLLATE "C". p_limit accepts 0–1000. Pass the last key of a page as p_after_key to fetch the next page. Historical versions and S3 delimiter rollups are not exposed here.

delete_object

silo_api.delete_object(
  p_bucket text, p_key text,
  p_version_id uuid DEFAULT NULL, p_if_match text DEFAULT NULL
)
RETURNS TABLE (
  deleted boolean, version_id uuid, is_delete_marker boolean
)

Requires DELETE on the bucket (plus SELECT when p_if_match is set). Omitting p_version_id either removes the current object or inserts a delete marker according to the bucket’s versioning state. Specifying p_version_id deletes that version unless blocked by Object Lock retention or legal hold (SL003).

copy_object

silo_api.copy_object(
  p_src_bucket text, p_src_key text,
  p_dst_bucket text, p_dst_key text,
  p_src_version_id uuid DEFAULT NULL,
  p_if_none_match boolean DEFAULT false,
  p_if_match text DEFAULT NULL
)
RETURNS TABLE (
  object_id bigint, version_id uuid, etag text,
  size bigint, mod_time timestamptz
)

Requires SELECT on the source bucket and INSERT on the destination bucket (plus destination SELECT when a destination condition is set). Reads the source body, tags, public metadata, and annotations from a single snapshot and publishes the destination object and annotations atomically. Rejects encrypted source objects or encrypted annotations.

Bucket functions

create_bucket

silo_api.create_bucket(
  p_name text, p_region text DEFAULT 'us-east-1'
)
RETURNS TABLE (
  name text, created_at timestamptz, region text, acl_relation regclass
)

Controlled by EXECUTE privilege on silo_api.create_bucket(text, text). Bucket names must be valid lowercase S3 names (3–63 bytes). Empty region defaults to 'us-east-1'; 'EU' maps to 'eu-west-1'. The creator receives SELECT, INSERT, and DELETE on the new acl_relation in silo_bucket.

bucket_info and list_buckets

silo_api.bucket_info(p_name text)
RETURNS TABLE (
  name text, created_at timestamptz, region text,
  versioning text, acl_relation regclass
)

silo_api.list_buckets()
RETURNS TABLE (
  name text, created_at timestamptz, region text,
  versioning text, acl_relation regclass
)

Filtered by the caller’s bucket privileges: holding at least one of SELECT, INSERT, or DELETE on a bucket’s ACL relation makes that bucket visible. bucket_info raises 42501 if the bucket does not exist or the caller lacks privileges.

drop_bucket

silo_api.drop_bucket(p_name text) RETURNS void

Requires DELETE on the bucket ACL relation and requires the bucket to be completely empty (no current objects, historical versions, or delete markers). There is no force parameter in SQL.

Errors and retries

Classify failures by SQLSTATE code rather than error message text:

SQLSTATEMeaningApplication handling
42501Role, function, or bucket permission deniedFix role bindings and GRANT statements; do not retry
22023Invalid argument, byte range, condition, or metadataFix caller input
0A000Unsupported write isolation level, encrypted payload, or unsynchronized bucket policyUse Read Committed for writes; use S3 API for encrypted objects
SO001Object body or version does not exist (or is a delete marker)Handle missing object
SO002ETag condition or p_object_id mismatchRe-read current state and decide whether to retry
SO003Object exceeds the 256 MiB inline SQL limitUse read_object chunked reads or the S3 API
SO004Incomplete object segment dataAbort and inspect storage consistency
SB001 / SB002 / SB003Bucket missing / bucket not empty / bucket already existsHandle at the application level
SL003Version protected by Object Lock retention or legal holdKeep protected version; SQL has no governance bypass
SL004Bucket or object lock state not yet synchronizedVerify compatible gateway processes are running
SQ001Hard bucket quota exceededFree logical space or increase bucket quota
SA004Annotation payload integrity failureReject corrupt payload and inspect storage

See the SQL Object Operations tutorial for end-to-end transactional examples.

Scan to open this page
https://mimus.pgsty.com/docs/s3/reference/sql-api/