On Fri, Mar 7, 2014 at 7:38 AM, Zsbán Ambrus <amb...@math.bme.hu> wrote:
> On 3/7/14, RSmith <rsm...@rsweb.co.za> wrote:
>> Add to this the fact that you can - through SQL's ability to add
>> user-defined functions (an almost unique ability among SQL engines)
>
> Is that really so?  I thought most sql engines had that.  You can
> define functions in at least postgreSQL:
>     http://www.postgresql.org/docs/9.3/interactive/xfunc.html

You can only define custom SQL function in C in SQLite.

The SQLite core lacks a built-in "scripty" engine which would allow it
to define new SQL function in "SQL/scripty", unlike most
bigger/heavier RDBMSs.

I think what SQLite lacks is a syntax to define custom function like
it does for virtual tables. Something like:

create function rpad(x, y) using scripty_module as "return PRINTF('%-*s',y,x)";

This above statement would have SQLite call some API on scripty_module
in charge of registering a function_pointer+userdata+userdatadelfunc
using the usual SQLite api to register custom functions, and
scripty_module will have to "compile" or "interpret" the function's
"code" (e.g. "return PRINTF('%-*s',y,x)") and run it with the supplied
sqlite3_value[] it receives (including unpacking the args to the
correct type the scripty function expects).

extension modules can also add custom functions, but a fixed set of
hard-coded functions. It could of course export a function that does
the equivalent of the "create function" SQL I dreamed up/showed above,
but then there's no standard/unified way to write custom scripty
functions, because of course we'd have a scripty_module to write
functions in js/lua/python/ruby/tcl/etc...

The SQLite core team extensively uses TCL already, so they could do a
proof-of-concept with TCL.

Most scripting languages wrap SQLite inside, but here I'm talking
about the reverse, it would be SQLite wrapping the scripting language
to SQL extensions, usable from the command-line sqlite3 familiar tool.
Again, it's already possibly now via extension module, but an official
syntax for scripted extension SQL functions, with readily available
such modules would improve the SQLite ecosystem IMHO.

--DD
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to