Skip to content
Advertisement

ppgsql declaring variable from parameter

I am running a sql query from the command line where I pass in value called tablename:

I then set the variable like this:

And then I have a function where I want to use the variable tablename like this:

I have also tried declaring the variable with a few variations of this:

Please let me know if you have any suggestions. I get the following error:

Advertisement

Answer

Your code cannot to work, because you try to read client side variables (psql) on server side (plpgsql). You need to push the value to custom server side variable, and in next step you can read it from plpgsql environment:

You cannot to use a psql syntax :var inside plpgsql code.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement