Skip to content

Commit 4f5eb43

Browse files
committed
Add OWNER TO clause to alter-trigger.md and update documentation for
task and trigger execution identity
1 parent 09706f4 commit 4f5eb43

4 files changed

Lines changed: 40 additions & 18 deletions

File tree

docs-site/reference/sql/statements/alter-trigger.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ description: SQL ALTER TRIGGER statement syntax and examples for suspending and
55

66
# ALTER TRIGGER
77

8-
The `ALTER TRIGGER` statement suspends or resumes one trigger.
8+
The `ALTER TRIGGER` statement suspends or resumes one trigger, or transfers the identity
9+
its unattended runs execute as.
910

1011
A suspended trigger still exists and is still reached when its table commits; it simply
1112
enqueues nothing and records that it was suppressed. Prefer this to
@@ -19,6 +20,10 @@ deliberately, when, and by whom.
1920
ALTER TRIGGER <trigger_name>
2021
ON <table_name>
2122
{ SUSPEND | RESUME };
23+
24+
ALTER TRIGGER <trigger_name>
25+
ON <table_name>
26+
OWNER TO { <principal> | CURRENT_USER };
2227
~~~
2328

2429
## Parameters
@@ -29,6 +34,9 @@ ALTER TRIGGER <trigger_name>
2934
`<workspace>.<collection>.<table_name>`.
3035
- `SUSPEND` — stop the trigger firing, keeping it in place.
3136
- `RESUME` — let it fire again.
37+
- `OWNER TO` — transfer the identity the trigger's runs execute as. The incoming owner
38+
must be a user or a service account — platform identities are refused, because they
39+
carry no billing account and the trigger's runs are billed to its owner.
3240

3341
## Examples
3442

@@ -42,6 +50,11 @@ ALTER TRIGGER ingest_on_events ON my_workspace.raw.events SUSPEND;
4250
ALTER TRIGGER ingest_on_events ON my_workspace.raw.events RESUME;
4351
~~~
4452

53+
### Transfer Its Owner
54+
~~~sql
55+
ALTER TRIGGER ingest_on_events ON my_workspace.raw.events OWNER TO svc_ingest;
56+
~~~
57+
4558
## Notes
4659

4760
- Requires the `writer` role on the table the trigger is attached to, the same as creating

docs-site/reference/sql/statements/create-task.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ re-runs one `SELECT` into its own backing table, a task runs any statement the e
1313
plan — typically an `INSERT` that appends only what changed, which is what makes it
1414
suitable for tables too large to rebuild.
1515

16-
A task runs as its owner, so creating one is not merely registering some SQL: it creates
17-
something that executes with an identity. What you may define is therefore bounded by what
18-
you could already run yourself — see [Notes](#notes).
16+
A task carries no identity of its own. Running one with [EXECUTE](execute) runs it as
17+
**you**, gated by your own permissions at that moment; an unattended run carries the
18+
identity of the [trigger](create-trigger) that fired it. Creating a task therefore
19+
confers no authority — see [Notes](#notes).
1920

2021
## Syntax
2122

@@ -37,7 +38,8 @@ CREATE [ OR REPLACE ] TASK <task_name>
3738
- **`<statement>`** — the SQL the task runs. It may contain `:name` placeholders, which are
3839
supplied when the task is executed rather than now.
3940
- `OR REPLACE` — redefine an existing task instead of refusing. The previous statement is
40-
kept as an earlier version, and the task's owner is **not** changed.
41+
kept as an earlier version, and triggers pointing at the task are untouched — including
42+
whose identity they run it as.
4143

4244
## Examples
4345

@@ -78,16 +80,14 @@ CREATE OR REPLACE TASK my_workspace.ops.ingest_events AS
7880

7981
## Notes
8082

81-
- **You may only create a task you could run yourself.** Creating one requires `reader` on
82-
everything the statement reads and `writer` where it writes, checked against you at the
83-
time you create it and again every time you redefine it. Without that, a task would let
84-
anyone define work over data they cannot see and have a privileged identity run it.
85-
- **The task runs as you.** There is no syntax for naming another principal — an argument
86-
that could is the escalation above, written out. Ownership survives `OR REPLACE`, so
87-
editing a task never quietly transfers whose authority it runs with.
88-
- **Platform identities cannot own tasks.** They can read a great deal but have no billing
89-
account, so a task pinned to one would run on a schedule forever and land on nobody's
90-
bill. Own a task as a user or a service account.
83+
- **Creating a task checks nothing but the name.** A task is stored SQL: its statement is
84+
gated when it *runs*, against whoever the run actually is — you, for `EXECUTE`; the
85+
trigger's owner, for a fired run. A creation-time copy of those checks would be checked
86+
against the wrong principal the moment anyone else ran it.
87+
- **`ON <table>` is the exception**, because it creates a trigger — and a trigger's
88+
unattended runs execute as its owner, pinned to you. So the `ON` form additionally
89+
requires `writer` on that table and that you are an identity that can be billed, the
90+
same gates [CREATE TRIGGER](create-trigger) applies.
9191
- The statement is parsed when the task is created, so SQL that could never run is refused
9292
now rather than discovered when it fires. It is not fully planned — a task's placeholders
9393
have no values yet, and planning would demand them.

docs-site/reference/sql/statements/create-trigger.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ CREATE OR REPLACE TRIGGER ingest_on_events
6363
## Notes
6464

6565
- Requires the `writer` role on the **table** the trigger is attached to — landing a
66-
trigger is an update to that table. It does not require any permission on the task: a
67-
trigger confers no authority of its own, and what the task may do was settled against its
68-
author when the task was created.
66+
trigger is an update to that table.
67+
- **The trigger's runs execute as its owner, which is pinned to you.** The trigger is what
68+
makes a run unattended, so the trigger is what names whose authority the run carries.
69+
The task's statement is gated against that owner every time it fires — nothing is
70+
settled once at creation and left to go stale. Move the owner with
71+
[ALTER TRIGGER ... OWNER TO](alter-trigger).
72+
- **Platform identities cannot own triggers.** They can read a great deal but have no
73+
billing account, so work pinned to one would run on a schedule forever and land on
74+
nobody's bill. Own a trigger as a user or a service account.
6975
- A fired task is passed the committing snapshot and its parent, as `:current_version` and
7076
`:parent_version`. The window is fixed when the trigger fires, so a run means the same
7177
thing however long afterwards it is picked up.

docs-site/reference/sql/statements/execute.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ EXECUTE my_workspace.ops.ingest_new
5353

5454
## Notes
5555

56+
- **The task runs as you.** `EXECUTE` is an attended run: the statement is gated against
57+
your own permissions, exactly as if you had typed it. Only an unattended run — a
58+
[trigger](create-trigger) firing — carries a pinned identity, the trigger's owner.
5659
- Arguments must be **constants**. A column reference is refused: a task's arguments are
5760
bound when it runs, not evaluated against a relation.
5861
- Values are substituted into the task's statement only after that statement has been

0 commit comments

Comments
 (0)