SQLite Forum

sqlite3.exe - ".expert" - no such function: REGEXP
Login

sqlite3.exe - ".expert" - no such function: REGEXP

(1.2) By Horst (neubauer) on 2023-09-15 21:00:02 edited from 1.1 [link] [source]

sqlite3 ".expert" command returns "no such function: REGEXP" for each sql command containing 'REGEXP'

sqlite> .expert
sqlite> select * from sqlite_master where sql REGEXP '.*table.*';
Error: no such function: REGEXP

sqlite> select sqlite_version();
3.43.1

(2) By Larry Brasfield (larrybr) on 2023-09-16 00:19:19 in reply to 1.2 [link] [source]

The "expert" extension needs a little more work to support SQL with user-defined functions. (aka "UDFs") Currently, it creates a temporary DB (with a private connection to use it) and replicates certain aspects of the user's DB to that temporary DB so that index suggestions can be formulated. However, the extension does not register the set of UDFs with the new connection that are registered with the user's DB connection. Hence, those UDFs are unknown as the expert extension does its compilation. This same issue arises with a slew of other UDFs that the shell always registers for user connections.

I'm not sure when (or if) this will be fixed. The feature is marked "EXPERIMENTAL", and has always had this limitation. I will have more to say on this after consultation with the development team.

Nevertheless, thanks for the report.

(3) By SeverKetor on 2023-09-16 01:44:36 in reply to 2 [link] [source]

Would it make sense to have .expert pretend to have any undefined functions it comes across? Or depending on how it works, have it register some dummy function when it comes across an undefined function error, then retry?

(5) By Stephan Beal (stephan) on 2023-09-16 07:15:59 in reply to 3 [link] [source]

Would it make sense to have .expert pretend to have any undefined functions it comes across? Or depending on how it works, have it register some dummy function when it comes across an undefined function error, then retry?

The attributes of a function, e.g. whether or not it's deterministic, can be used by the query planner and having .expert mode stub those would cause it, at times, to give different results than without .expert, which would cause more confusion than it solved.

(4) By anonymous on 2023-09-16 05:11:18 in reply to 2 [link] [source]

I would argue that the work needed is not little, I genuinely tried making it work before and gave up after a while

(6.1) By Larry Brasfield (larrybr) on 2023-09-24 20:10:26 edited from 6.0 in reply to 2 [link] [source]

This reported difficulty with .expert, along with a similar one, has been fixed on the repo trunk.

With the changes, all UDFs registered with a connection given to the expert extension are also registered, by name and type (but not implementation1), with the temporary DBs that expert uses for its machinations. Further, provided that user-provided SQL compiles against the user connection, any custom collation sequence used in that SQL is stubbed out.2

There was a theoretic difficulty with "replicating" UDFs. A UDF can be either of types "scalar", "aggregate" or "window", or some combinations thereof. The replication, relying as it does on pragma_function_list() results, can only create the first three of those possible types as stand-ins. This might, conceivably, affect a query plan to a degree that would affect index recommendations. This was adjudged unlikely to happen, and if it does it is likely a minor effect. So, since expert's effort was always a "best effort", this theoretic shortcoming has been deemed acceptable. The alternative was to mess with SQLite library interfaces to support digging out complete UDF characteristics. That was deemed a step too far for today.


  1. ^ There is no need for any UDF implementation; the compiled SQL is never run.
  2. ^ Because the compiled SQL is not run, the stub is never called, so it do-nothing nature does not matter.

(7) By SeverKetor on 2023-09-24 22:28:34 in reply to 6.1 [link] [source]

Went to try it out and gcc is throwing "parameter name omitted" errors in the new code, for a few new functions.

shell.c: In function 'dummyCompare':
shell.c:12850:18: error: parameter name omitted
 int dummyCompare(void*, int, const void*, int, const void*){
                  ^~~~~
shell.c:12850:25: error: parameter name omitted
 int dummyCompare(void*, int, const void*, int, const void*){
                         ^~~
shell.c:12850:30: error: parameter name omitted
 int dummyCompare(void*, int, const void*, int, const void*){
                              ^~~~~~~~~~~
shell.c:12850:43: error: parameter name omitted
 int dummyCompare(void*, int, const void*, int, const void*){
                                           ^~~
shell.c:12850:48: error: parameter name omitted
 int dummyCompare(void*, int, const void*, int, const void*){
                                                ^~~~~~~~~~~
shell.c: In function 'useDummyCS':
shell.c:12854:17: error: parameter name omitted
 void useDummyCS(void *, sqlite3 *db, int etr, const char *zName){
                 ^~~~~~
shell.c: In function 'dummyUDF':
shell.c:12863:15: error: parameter name omitted
 void dummyUDF(sqlite3_context*,int,sqlite3_value**){
               ^~~~~~~~~~~~~~~~
shell.c:12863:32: error: parameter name omitted
 void dummyUDF(sqlite3_context*,int,sqlite3_value**){
                                ^~~
shell.c:12863:36: error: parameter name omitted
 void dummyUDF(sqlite3_context*,int,sqlite3_value**){
                                    ^~~~~~~~~~~~~~~
shell.c: In function 'dummyUDFvalue':
shell.c:12866:20: error: parameter name omitted
 void dummyUDFvalue(sqlite3_context*){
                    ^~~~~~~~~~~~~~~~

(8) By Larry Brasfield (larrybr) on 2023-09-24 22:54:28 in reply to 7 [link] [source]

Thanks for that report. Please try next check-in, reflecting my reversion to the C89 mindset.

(9) By SeverKetor on 2023-09-24 23:16:55 in reply to 8 [link] [source]

Yep, it compiled just fine this time around.
I still have a "no such function" issue though, presumably because I have virtual columns with UDFs. When I use .expert, it immediately gives sqlite3_expert_new: no such function: IP_TO_INT. Not sure if this is beyond the scope of what you wanted to do though

(10) By Larry Brasfield (larrybr) on 2023-09-24 23:34:30 in reply to 9 [link] [source]

compiled just fine

Thanks.

I still have a "no such function" issue though, presumably because I have virtual columns with UDFs. ...

I do not see why this should matter. Can you please provide a repro sequence in the CLI, using one of its UDFs (such as result from "select name from pragma_function_list where builtin=0;")?

Not sure if this is beyond the scope of what you wanted to do though

The intent is to make expert work with UDFs as well as with BIFs.

(11) By SeverKetor on 2023-09-25 00:15:01 in reply to 10 [source]

CREATE TABLE t (Str TEXT, SomeColumnName AS (REGEXP('aaa', Str)));
.expert
sqlite3_expert_new: no such function: REGEXP

(12) By Larry Brasfield (larrybr) on 2023-09-25 00:43:18 in reply to 11 [link] [source]

Thanks for the repro. This defect is fixed now.

I did not realize that UDF lookups could occur during the schema copy that happens when .expert is executed. So I learned something today.

(13) By SeverKetor on 2023-09-25 02:12:12 in reply to 12 [link] [source]

Nice, that fixed that issue. Unfortunately, I did accidentally find one more. Virtual tables cause .expert to fail immediately as well. sqlite3_expert_new: no such module: csv

Easily solved for me by just removing the virtual table I forgot about, but could be annoying for others.