In a function, I have a SELECT
query in a string, for example:
sql='SELECT * FROM A'
I want to execute sql
output result of: SELECT * FROM A
How can I execute the string sql
in PostgreSQL?
Inside a function use EXECUTE.
http://www.postgresql.org/docs/current/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
below one works fine in postgres 8.4
UDBI=> PREPARE query as select 1 as a;
PREPARE
UDBI=> PREPARE query
UDBI=> EXECUTE query;
a
---
1
(1 row)
UDBI=>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With