Skip to content

Commit a57fef1

Browse files
Nguyễn Phúc Lươngclaude
andcommitted
refactor(ast): add named DropBehavior constants
The pg_query DropBehavior enum currently lives as a bare `type DropBehavior uint` — callers that compare against the wire values have to write magic numbers (`stmt.Behavior == 2` for CASCADE). Add named constants matching pganalyze/pg_query_go's DropBehavior enum so usage sites can read `stmt.Behavior == ast.DropBehaviorCascade` instead, and survive a future pg_query enum reshuffle without silently miscompiling. No behavior change — just constants. Existing code that compares to integer literals continues to work; this is purely additive. Follow-up to the review on #4419 (which currently uses `Behavior == 2` literal): happy to apply the same rename in that PR's diff once it lands, or in a separate sweep PR depending on what the maintainers prefer. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a3b0cfd commit a57fef1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

internal/sql/ast/drop_behavior.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
package ast
22

3+
// DropBehavior captures whether a Postgres DROP statement was qualified with
4+
// RESTRICT or CASCADE. The numeric values mirror pganalyze/pg_query_go's
5+
// DropBehavior enum:
6+
//
7+
// DropBehavior_UNDEFINED = 0 (no behavior word supplied — same as RESTRICT in PG)
8+
// DROP_RESTRICT = 1
9+
// DROP_CASCADE = 2
310
type DropBehavior uint
411

12+
const (
13+
DropBehaviorUndefined DropBehavior = 0
14+
DropBehaviorRestrict DropBehavior = 1
15+
DropBehaviorCascade DropBehavior = 2
16+
)
17+
518
func (n *DropBehavior) Pos() int {
619
return 0
720
}

0 commit comments

Comments
 (0)