sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

Reconstruct statement

Open mtangoo opened this issue 5 years ago • 4 comments

Hi, thank you for this wonderful library. I just started today an am already enjoying using it. I have a use case where I have statement like SELECT a,b,c FROM users WHERE a > 1

Now suppose I want to reconstruct the SQL query string removing WHERE and replacing Select columns with let say * so that the statement becomes: SELECT * FROM users

I know the library provides a list of statements (where I can choose which one I don't want to have them but then how do I glue the wanted pieces into a complete statement?

TIA, Stefano

mtangoo avatar Dec 09 '19 18:12 mtangoo

Hi Stefano,

glad that the library is of use to you. Just to clarify: Is your expected output another SQL statement? If yes, that is not something that we support at the moment.

It should not be too complex to add operator<< methods to the different classes and recreate a SQL statement. Once that is done, actually replacing the columns (SelectStatement::selectList) with a single * is straight forward.

mrks avatar Dec 10 '19 10:12 mrks

Hi, I don't expect full statement but rather building blocks. For example from Select I can get the table and columns. That's enough to build Select statement. In where I could get conditions, et al.

Are those things available already (I know I can get the table from one issue I found on repo)

mtangoo avatar Dec 10 '19 15:12 mtangoo

I know I can get the table from one issue I found on repo

Could you give me a link? Maybe that will help me understand better what you are looking for.

mrks avatar Dec 11 '19 12:12 mrks

OK I will put exhaustive explanation when at home!

mtangoo avatar Dec 11 '19 17:12 mtangoo