plpgsql function-parsing

Started by chrisabout 8 years ago2 messagesgeneral
Jump to latest
#1chris
chrisk@pgsqlrocket.com

Hi,

I am trying to create a function that gets passed a statement as a
string and then I need to change the table_name within the string by
adding a "_cdc" to it, then execute the statement

ex:

string passed could be GRANT all ON authors TO bob.

then

EXECUTE GRANT all ON authors_cdc TO bob

I'm looking into parsing the string but i can't find a way to parse in a
way that'll work. Any ideas?

Thanks,

Chris

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: chris (#1)
Re: plpgsql function-parsing

Hi

2018-03-06 16:51 GMT+01:00 chris <chrisk@pgsqlrocket.com>:

Hi,

I am trying to create a function that gets passed a statement as a string
and then I need to change the table_name within the string by adding a
"_cdc" to it, then execute the statement

ex:

string passed could be GRANT all ON authors TO bob.

then

EXECUTE GRANT all ON authors_cdc TO bob

I'm looking into parsing the string but i can't find a way to parse in a
way that'll work. Any ideas?

The extension Orafce https://github.com/orafce/orafce has some basic
library for parsing SQL PLVlex.

Another solution can be using regular expressions
https://www.postgresql.org/docs/current/static/functions-matching.html

Regards

Pavel

Show quoted text

Thanks,

Chris