Home / Learn Secure SQL / The Stored-Procedure-Only Access Pattern

The Stored-Procedure-Only Access Pattern

An account that can only call specific procedures, nothing else directly.

Quick summaryAn account that can only call specific procedures, nothing else directly.

How to think about this

Two access modelsDirect table grantsFlexible: ad hocSELECT/INSERT/UPDATEAny query shape the account'sgrants allowProcedure-only grantsAccount can only call approvedproceduresEvery operation is pre-definedand reviewed
Two access models

Definition

In this pattern, an account is granted EXECUTE on a specific set of stored procedures/functions, but no direct SELECT/INSERT/UPDATE/DELETE on the underlying tables at all — every interaction must go through an approved procedure.

Why you need this

This centralises and constrains exactly what operations are possible, which can be valuable for especially sensitive tables, at the cost of extra development overhead for every new kind of query.

How it works

Grant EXECUTE on a curated set of procedures only; revoke direct table access entirely for that account, and write new procedures (with their own safe, parameterised internals, as covered earlier) as new needs arise.

Where you'll see this

  • Web application code review
  • Backend development
  • Database administration
A procedure-only grant (illustrative, PostgreSQL)
REVOKE ALL ON accounts FROM teller_app;
GRANT EXECUTE ON FUNCTION transfer_funds(int, int, numeric) TO teller_app;
-- teller_app can only ever call transfer_funds(...), never query accounts directly

Test what you just read

1. In the stored-procedure-only pattern, an account typically has...