Reputation: 4192
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);
Upvotes: 1
Views: 8892
Reputation: 1298
A simple example:
DO $$
DECLARE
myVar VARCHAR := myValue;
BEGIN
INSERT INTO table(user) VALUES (myVar);
END $$;
Upvotes: 2