3

I have a query string in variable

suppose Select Now(); I want to execute it same like SQL do. I use

Execute 'Select Now()';

But It throws an exception

prepared statement "SELECT now()" does not exist

and not allow me to execute it.

Is there any way to do that?

4
  • Please show us your complete function Commented Dec 1, 2016 at 10:25
  • This is simplest one I tried. I will make function if it execute. Commented Dec 1, 2016 at 10:26
  • you can't use execute in SQL, this is a PL/pgSQL statement. You need a function (or a do block) Commented Dec 1, 2016 at 10:30
  • Possible duplicate of dynamic sql query in postgres Commented Dec 1, 2016 at 10:33

2 Answers 2

1

You mess plpgsql EXECUTE:

t=# do $$ begin execute 'select now()'; end; $$;
DO

and SQLEXECUTE.

t=# prepare example as select now();
PREPARE
t=# execute example;
              now
-------------------------------
 2016-12-01 10:30:15.782433+00
(1 row)
Sign up to request clarification or add additional context in comments.

1 Comment

I am using pgAdmin. How it execute in it?
-1

'Select Now()' Run like this in pgadmin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.