File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -105,3 +105,22 @@ var ParseQualifiedTableName = func(sql string) (*tree.TableName, error) {
105105var PLpgSQLParse = func (sql string ) (statements.PLpgStatement , error ) {
106106 return statements.PLpgStatement {}, errors .AssertionFailedf ("sql.DoParserInjection hasn't been called" )
107107}
108+
109+ // FingerprintStatement parses a SQL string and converts it to a statement
110+ // fingerprint. If the input is already a fingerprint, it is returned as-is.
111+ // The optional extraFlags are OR'd into the default FmtHideConstants flags used
112+ // for fingerprinting.
113+ func FingerprintStatement (sql string , extraFlags ... tree.FmtFlags ) (string , error ) {
114+ stmts , err := Parse (sql )
115+ if err != nil {
116+ return "" , pgerror .Wrapf (
117+ err , pgcode .InvalidParameterValue , "could not parse statement" ,
118+ )
119+ }
120+ if len (stmts ) != 1 {
121+ return "" , pgerror .Newf (
122+ pgcode .InvalidParameterValue , "could not parse as a single SQL statement" ,
123+ )
124+ }
125+ return tree .FormatStatementHideConstants (stmts [0 ].AST , extraFlags ... ), nil
126+ }
You can’t perform that action at this time.
0 commit comments