SQL API
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 ROLEis rejected. The installation owner (silo_owner) and its role members cannot callsilo_apifunctions. - Callers need
USAGEonsilo_api,EXECUTEon each required function, and the corresponding table privileges on the bucket’s ACL relation insilo_bucket. Functions are not granted toPUBLIC. See Authorization. - Write functions require
Read Committed(or PostgreSQLRead Uncommitted, which behaves identically). Calling write functions underRepeatable ReadorSerializableraisesSQLSTATE 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
byteabodies are valid. Passing SQLNULLforp_version_idtargets the current version. To target an S3nullversion explicitly, pass UUID'00000000-0000-0000-0000-000000000000'(not the string'null'). - Inline
put_object,get_object, andcopy_objectbodies are capped atmin(SILO_PG_MAX_OBJECT_SIZE, 256 MiB).read_objectreturns at most8 MiB(8388608bytes) 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
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
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
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
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
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
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
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
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
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
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:
| SQLSTATE | Meaning | Application handling |
|---|---|---|
42501 | Role, function, or bucket permission denied | Fix role bindings and GRANT statements; do not retry |
22023 | Invalid argument, byte range, condition, or metadata | Fix caller input |
0A000 | Unsupported write isolation level, encrypted payload, or unsynchronized bucket policy | Use Read Committed for writes; use S3 API for encrypted objects |
SO001 | Object body or version does not exist (or is a delete marker) | Handle missing object |
SO002 | ETag condition or p_object_id mismatch | Re-read current state and decide whether to retry |
SO003 | Object exceeds the 256 MiB inline SQL limit | Use read_object chunked reads or the S3 API |
SO004 | Incomplete object segment data | Abort and inspect storage consistency |
SB001 / SB002 / SB003 | Bucket missing / bucket not empty / bucket already exists | Handle at the application level |
SL003 | Version protected by Object Lock retention or legal hold | Keep protected version; SQL has no governance bypass |
SL004 | Bucket or object lock state not yet synchronized | Verify compatible gateway processes are running |
SQ001 | Hard bucket quota exceeded | Free logical space or increase bucket quota |
SA004 | Annotation payload integrity failure | Reject corrupt payload and inspect storage |
See the SQL Object Operations tutorial for end-to-end transactional examples.
