MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / SQL

Method SQL

pkg/sql/ast/sql.go:1072–1116  ·  view source on GitHub ↗

SQL returns the full SQL string for this MERGE statement including the target, source, ON condition, and all WHEN MATCHED/NOT MATCHED clauses.

()

Source from the content-addressed store, hash-verified

1070// SQL returns the full SQL string for this MERGE statement including the target,
1071// source, ON condition, and all WHEN MATCHED/NOT MATCHED clauses.
1072func (m *MergeStatement) SQL() string {
1073 if m == nil {
1074 return ""
1075 }
1076 sb := getBuilder()
1077 defer putBuilder(sb)
1078 sb.WriteString("MERGE INTO ")
1079 sb.WriteString(tableRefSQL(&m.TargetTable))
1080 if m.TargetAlias != "" {
1081 sb.WriteString(" ")
1082 sb.WriteString(m.TargetAlias)
1083 }
1084 sb.WriteString(" USING ")
1085 sb.WriteString(tableRefSQL(&m.SourceTable))
1086 if m.SourceAlias != "" {
1087 sb.WriteString(" ")
1088 sb.WriteString(m.SourceAlias)
1089 }
1090 sb.WriteString(" ON ")
1091 sb.WriteString(exprSQL(m.OnCondition))
1092
1093 for _, when := range m.WhenClauses {
1094 sb.WriteString(" WHEN ")
1095 switch when.Type {
1096 case "MATCHED":
1097 sb.WriteString("MATCHED")
1098 case "NOT_MATCHED":
1099 sb.WriteString("NOT MATCHED")
1100 case "NOT_MATCHED_BY_SOURCE":
1101 sb.WriteString("NOT MATCHED BY SOURCE")
1102 default:
1103 sb.WriteString(when.Type)
1104 }
1105 if when.Condition != nil {
1106 sb.WriteString(" AND ")
1107 sb.WriteString(exprSQL(when.Condition))
1108 }
1109 sb.WriteString(" THEN ")
1110 if when.Action != nil {
1111 sb.WriteString(mergeActionSQL(when.Action))
1112 }
1113 }
1114
1115 return sb.String()
1116}
1117
1118// DML types from dml.go
1119

Callers 3

TestMergeStatement_SQLFunction · 0.95
TestNilSQLFunction · 0.95

Calls 6

getBuilderFunction · 0.85
putBuilderFunction · 0.85
mergeActionSQLFunction · 0.85
tableRefSQLFunction · 0.70
exprSQLFunction · 0.70
StringMethod · 0.45

Tested by 3

TestMergeStatement_SQLFunction · 0.76
TestNilSQLFunction · 0.76