Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIs it feasible to add support in jsqlparser for "table-valued" functions as defined by t-sql? #715
Comments
Function creation or definition is not supported. In fact this is TSql and not Sql alone. JSqlParser is only a Sql parser . |
Thanks for your prompt reply. I don't have any experience working with parser grammars and so it's all a little opaque to me. And forgive me if my terminology here is incorrect. I understand that jsqlParser is only a parser. The question whether it is feasible to extend the syntax/grammar that jsqlParser recognizes to include that particular construct supported by tsql. I also understand that the visitor patterns in jsqlParser would require extension as well. That part I can probably handle if pointed in the right direction. |
To be clear, I'm using the existing abilities of jsqlparser to parse function syntax and it's working very well for me although what I'm doing isn't traditional SQL usage. The particular problem I'm trying to solve is creating a function that yields a table-valued result and using that to create a view or temporary table (for example, interpolating the data for a result table from two input vectors). The argument processing and table manipulation is all part of my problem domain so I don't expect anything from jsqlparser on part of the solution. |
Are you talking about the complete create or replace function construct or only about the SQL parts within it? |
I'm not sure I understand your question. I'm interested in the "RETURNS TABLE" part of the construct. Given that the use-case is to populate a view with the output of a function, I'm open to suggestions about the best way to do this. I just need an SQL construct that can be parsed, ideally by jsqlparser, and semantics that align with conventional usage. An ugly (to my mind) alternative, is to pass the name of a table into the function and just implement the function so that it knows how to create a table. This is viable for me to implement but seems a little opaque from a user perspective as relates to a fairly substantial side-effect (creating a table) If you have suggestions about which approach is better or some other SQL construct entirely I'd be grateful |
From t-sql
-- Transact-SQL Multi-Statement Table-Valued Function Syntax
CREATE [ OR ALTER ] FUNCTION [ schema_name. ] function_name
( [ { @parameter_name [ AS ] [ type_schema_name. ] parameter_data_type
[ = default ] [READONLY] }
[ ,...n ]
]
)
RETURNS @return_variable TABLE <table_type_definition>
[ WITH <function_option> [ ,...n ] ]
[ AS ]
BEGIN
function_body
RETURN
END
[ ; ]
If someone could suggest the how extend the grammar I can probably handle the rest of the library changes