Using SQL
You can use SQL directly with the run_sql function. This is useful for complex queries or when you need to use SQL features that are not supported by the abstra API.
Selecting
Timestamp precision and optimistic updates
By default, run_sql returns timestamp and timestamptz values as strings with millisecond precision. PostgreSQL can store microseconds, so the default result may not equal the stored timestamp when passed back to SQL. Do not round timestamps to compare versions: this can hide a concurrent update.
Use the keyword-only option timestamp_precision="full" to preserve PostgreSQL's full timestamp precision for that call:
With "full", timestamp values are returned as PostgreSQL text (for example, "2026-11-08 15:49:30.568158"), and timestamptz values include the database session's UTC offset (for example, "2026-11-08 15:49:30.568158+00"). The offset is not necessarily the one originally supplied when saving. Timestamp arrays preserve their shape and nulls; other types and query parameters are unchanged. Keep the returned string intact: parsing it through a millisecond-only date type loses precision again. Omitting the option, or passing None, keeps the existing behavior. Other Tables functions are unchanged.
For a timestamptz version column, use that exact string in a conditional update and check the rows returned:
Use ::timestamp instead of ::timestamptz if the column is a timestamp without time zone. Every writer must update the version column, and it must change on each write; timestamp precision alone does not enforce this. Use a dedicated version counter if that invariant cannot be guaranteed.
This option requires an SDK and backend version that support it. As an alternative available without the option, return the timestamp as text in SQL:
For a timestamp without time zone, to_char(updated_at, 'YYYY-MM-DD HH24:MI:SS.US') also preserves microseconds. For timestamptz, prefer ::text so the UTC offset is included. Pass this string back using the cast matching the column, as in the conditional update above.
Inserting
You can't modify the schema of a table using SQL. Use the Cloud Console to add or remove columns.