@@ -24,9 +24,36 @@ import (
2424
2525// initNextVal registers the functions to the catalog.
2626func initNextVal () {
27+ framework .RegisterFunction (nextval_text )
2728 framework .RegisterFunction (nextval_regclass )
2829}
2930
31+ // nextval_text represents the PostgreSQL function of the same name, taking the same parameters.
32+ //
33+ // TODO: Even though we can implicitly convert a text param to a regclass param, it's an expensive process
34+ // to convert it to a regclass, then convert the regclass back into the relation name, so we provide an overload
35+ // that takes a text param directly, in addition to the function form that takes a regclass. Once we can optimize
36+ // the regclass to text conversion, we can potentially remove this overload.
37+ var nextval_text = framework.Function1 {
38+ Name : "nextval" ,
39+ Return : pgtypes .Int64 ,
40+ Parameters : [1 ]pgtypes.DoltgresType {pgtypes .Text },
41+ IsNonDeterministic : true ,
42+ Strict : true ,
43+ Callable : func (ctx * sql.Context , _ [2 ]pgtypes.DoltgresType , val any ) (any , error ) {
44+ schema , sequence , err := parseRelationName (ctx , val .(string ))
45+ if err != nil {
46+ return nil , err
47+ }
48+
49+ collection , err := core .GetSequencesCollectionFromContext (ctx )
50+ if err != nil {
51+ return nil , err
52+ }
53+ return collection .NextVal (schema , sequence )
54+ },
55+ }
56+
3057// nextval_regclass represents the PostgreSQL function of the same name, taking the same parameters.
3158var nextval_regclass = framework.Function1 {
3259 Name : "nextval" ,
0 commit comments