First of all, thank you beforehand for helping me with this. Please do not state that this is a repeat question as I have searched a lot but still none of the threads I found here relate to my query. Actually I have a simple query which I'm failing to pass through and needed some help. My issue is as follows,
I want to run a simple SQL query to insert some data into a table i.e.,
INSERT INTO "public"."plan" (id,name,description) VALUES (6,"Plan Name","Plan Description");
But instead of passing Plan Name and Plan Description as text, I'm looking to define variables and pass those instead, in short something like this,
INSERT INTO "public"."plan" (id,name,description) VALUES (6,customPlanName,customPlanDescription);
I've tried using the following but this doesn't work,
DECLARE
planname TEXT;
plandesc TEXT;
SET planname = 'MidasName';
SET plandesc = 'PlanDescription';
INSERT INTO "public"."plan" (id,name,description) VALUES (6,planname,plandesc);
Can you please help me out with this? I want something to be run using PostgreSQL on PgAdmin III
Thank you in advance for any help provided.
example with prepared statements:
prepare plan_insert (text,text)
as INSERT INTO "public"."plan" (id,name,description) VALUES (6,$1,$2);
execute plan_insert ('MidasName','PlanDescription');
execute plan_insert ('Some Other','Some more');