Kandarp Khandwala
Kandarp Khandwala

Reputation: 1

How (if possible) to use PostgreSQL's parser (in C) independently?

I need a parser (mainly for the "select" type of queries) and avoid the hassle of doing it from scratch. Does anybody know how to use the scan.l/gram.y of pgsql for this purpose? I've looked up pgpool too, but it seems similar. Currently, it might be very helpful if someone could give instructions to compile the parser (using the makefile provided maybe) without errors so that it can be supplied (valid?) queries and outputs the parse tree (in whatever form)!

Upvotes: 0

Views: 471

Answers (2)

Chris Travers
Chris Travers

Reputation: 26454

PostgreSQL compiles the language parser using yacc. Presumably you could take the yacc files and create a compatible parser with very little effort. Note you must have flex and yacc installed to do this.

Note this is not taking a .c file from source and transplanting it into your system. All you are getting is the parser, not the planner or anything else.

Given the level of detail in the question no more detail can be possible. Perhaps you could start there and post another question when you get stuck.

Upvotes: 0

Pavel Stehule
Pavel Stehule

Reputation: 45750


You probably cannot take any file from postgres source tarball and compile it separately. Parser use internal OOP structures (implemented in C). But there is some possibility (not simple) - ecpg preprocessor try to transform PostgreSQL gram file to secondary gram file - and you can use same mechanism. It use a small utility parse.pl (it is part of PostgreSQL source code (src/postgresql/src/interfaces/ecpg/preproc))

Upvotes: 1

Related Questions