Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it feasible to add support in jsqlparser for "table-valued" functions as defined by t-sql? #715

Open
amacgaffey opened this issue Nov 20, 2018 · 5 comments

Comments

@amacgaffey
Copy link

@amacgaffey amacgaffey commented Nov 20, 2018

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

@wumpz
Copy link
Member

@wumpz wumpz commented Nov 22, 2018

Function creation or definition is not supported. In fact this is TSql and not Sql alone. JSqlParser is only a Sql parser .

@amacgaffey
Copy link
Author

@amacgaffey amacgaffey commented Nov 22, 2018

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.

@amacgaffey
Copy link
Author

@amacgaffey amacgaffey commented Nov 22, 2018

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.

@wumpz
Copy link
Member

@wumpz wumpz commented Nov 23, 2018

Are you talking about the complete create or replace function construct or only about the SQL parts within it?

@amacgaffey
Copy link
Author

@amacgaffey amacgaffey commented Nov 23, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.