MCPcopy Create free account
hub / github.com/dolthub/doltgresql / nodeCreateTrigger

Function nodeCreateTrigger

server/ast/create_trigger.go:36–121  ·  view source on GitHub ↗

nodeCreateTrigger handles *tree.CreateTrigger nodes.

(ctx *Context, node *tree.CreateTrigger)

Source from the content-addressed store, hash-verified

34
35// nodeCreateTrigger handles *tree.CreateTrigger nodes.
36func nodeCreateTrigger(ctx *Context, node *tree.CreateTrigger) (_ vitess.Statement, err error) {
37 if node.Constraint {
38 return NotYetSupportedError("CREATE CONSTRAINT TRIGGER is not yet supported")
39 }
40 if !node.RefTable.IsEmpty() {
41 return NotYetSupportedError("FROM is not yet supported for CREATE TRIGGER")
42 }
43 if node.Deferrable != tree.TriggerNotDeferrable {
44 return NotYetSupportedError("DEFERRABLE is not yet supported for CREATE TRIGGER")
45 }
46 if len(node.Relations) > 0 {
47 return NotYetSupportedError("REFERENCING is not yet supported for CREATE TRIGGER")
48 }
49 if !node.ForEachRow {
50 return NotYetSupportedError("FOR EACH STATEMENT is not yet supported for CREATE TRIGGER")
51 }
52 funcName := node.FuncName.ToTableName()
53 var timing triggers.TriggerTiming
54 switch node.Time {
55 case tree.TriggerTimeBefore:
56 timing = triggers.TriggerTiming_Before
57 case tree.TriggerTimeAfter:
58 timing = triggers.TriggerTiming_After
59 case tree.TriggerTimeInsteadOf:
60 return NotYetSupportedError("INSTEAD OF is not yet supported for CREATE TRIGGER")
61 }
62 var events []triggers.TriggerEvent
63 for _, event := range node.Events {
64 switch event.Type {
65 case tree.TriggerEventInsert:
66 events = append(events, triggers.TriggerEvent{
67 Type: triggers.TriggerEventType_Insert,
68 })
69 case tree.TriggerEventUpdate:
70 if len(event.Cols) > 0 {
71 return NotYetSupportedError("UPDATE specific columns are not yet supported for CREATE TRIGGER")
72 }
73 events = append(events, triggers.TriggerEvent{
74 Type: triggers.TriggerEventType_Update,
75 ColumnNames: event.Cols.ToStrings(),
76 })
77 case tree.TriggerEventDelete:
78 events = append(events, triggers.TriggerEvent{
79 Type: triggers.TriggerEventType_Delete,
80 })
81 case tree.TriggerEventTruncate:
82 return NotYetSupportedError("TRUNCATE is not yet supported for CREATE TRIGGER")
83 default:
84 return NotYetSupportedError("UNKNOWN EVENT TYPE is not yet supported for CREATE TRIGGER")
85 }
86 }
87 // WHEN expressions seem to behave identically to interpreted functions, so we'll parse them as interpreted functions.
88 // To do this, we need the raw string, and we wrap it as though it were a trigger function (which has special logic
89 // for handling NEW and OLD rows). Using a regex for this rather than modifying the parser may seem suboptimal, but
90 // we want to retain the parser validation of using an expression, however we cannot rely on the expression's
91 // String() function to return the **exact** same string, so we capture it with a regex.
92 var whenOps []plpgsql.InterpreterOperation
93 if node.When != nil {

Callers 1

ConvertFunction · 0.85

Calls 10

ParseFunction · 0.92
NewTriggerFunction · 0.92
NewFunctionFunction · 0.92
NotYetSupportedErrorFunction · 0.85
ToTableNameMethod · 0.80
ToStringsMethod · 0.80
SchemaMethod · 0.65
StringMethod · 0.65
IsEmptyMethod · 0.45
TableMethod · 0.45

Tested by

no test coverage detected