Objects from SQL
The SQL transaction API (silo_api) and PostgreSQL native authorization (silo_bucket) are Preview features in the MVP scope.
This tutorial writes an invoice row and its attachment in one PostgreSQL transaction, verifies both from SQL and S3, rolls back a second transaction, and reads paginated lists and object segments. Complete the Quick start first so the silo database and plaintext attachments bucket exist.
Create an application SQL role
Connect to silo as a database administrator and create an unprivileged login role (app_sql) and application schema (app_demo):
The application role needs no superuser rights, no membership in silo_owner, and no direct access to the private silo schema.
Next, connect to silo as the installation owner (silo_owner) and grant EXECUTE on the required silo_api functions plus SELECT and INSERT on the ACL relation for attachments:
In psql, \gexec executes the generated GRANT statement. Because a bucket’s ACL relation name in silo_bucket is decoupled from the bucket name, silo_owner looks it up through silo.bucket_acl. See Authorization for the complete permission mapping.
Reconnect as app_sql and create the business table:
silo_api checks the login-time session_user and rejects SET ROLE impersonation.
Commit a business row and object together
In the app_sql session, write an object and insert the referencing invoice row in one Read Committed transaction:
Read the committed object body and metadata from SQL:
Read the same object over S3:
get_object returns bytea. Use convert_from only when the payload is known UTF-8 text.
Roll back a business row and object together
Start a second transaction, write both the object and the invoice row, and roll back:
Both counts return 0. Neither the relational row nor the S3 object is published.
If your application needs a permanent reference to an immutable object body, enable bucket versioning and pass the saved version_id when calling get_object, stat_object or read_object. Overwriting an unversioned object replaces its body.
Paginate listings and read segments
List the first page of objects under the invoices/ prefix:
To fetch the next page, pass the final key of the current page as the third argument (start_after). Each call returns at most 1,000 live objects in C byte order and omits delete markers.
To read a large object in bounded chunks without materializing the full body in one call, open a read-only Repeatable Read snapshot and call read_object:
read_object returns at most 8 MiB (8388608 bytes) per call. Use REPEATABLE READ only for read-only transactions; SQL writes through silo_api require READ COMMITTED.
Direct SQL writes do not emit S3 bucket notifications. To publish events atomically with SQL object writes, insert into a transactional outbox table in the same transaction; see Multipart, Object Lock and STS and the SQL API reference.
