1

I have several queries in a query window in pgAdmin, many using the same value(s). Is there a way to declare a variable, myVar to use in query statements?

SELECT * FROM table WHERE user = myVar;
INSERT INTO table(user) VALUES (myVar);
asked Apr 20, 2017 at 23:48

1 Answer 1

2

A simple example:

DO $$
DECLARE 
 myVar VARCHAR := myValue; 
BEGIN 
 INSERT INTO table(user) VALUES (myVar);
END $$;
answered Apr 21, 2017 at 1:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.