MCPcopy Create free account
hub / github.com/PostHog/duckgres / stripCreateOrReplaceTable

Function stripCreateOrReplaceTable

transpiler/create_or_replace.go:32–38  ·  view source on GitHub ↗

stripCreateOrReplaceTable detects `CREATE OR REPLACE TABLE ...`. On a match it returns the PostgreSQL-parseable `CREATE TABLE ...` form (with OR REPLACE removed) and ok=true; the caller transpiles that through the normal pipeline and then restores OR REPLACE via reinjectOrReplace. Returns ok=false f

(sql string)

Source from the content-addressed store, hash-verified

30// and then restores OR REPLACE via reinjectOrReplace. Returns ok=false for any
31// other statement (including the PostgreSQL-valid `CREATE OR REPLACE VIEW`).
32func stripCreateOrReplaceTable(sql string) (inner string, ok bool) {
33 m := createOrReplaceTableRe.FindStringSubmatch(stripLeadingSQL(sql))
34 if m == nil {
35 return "", false
36 }
37 return "CREATE " + m[1], true
38}
39
40// reinjectOrReplace inserts `OR REPLACE` after the leading CREATE keyword of a
41// transpiled `CREATE [TEMP] TABLE ...` statement, reversing the strip done by

Callers 1

TranspileMethod · 0.85

Calls 1

stripLeadingSQLFunction · 0.85

Tested by

no test coverage detected