hello2345ji
IS-IT--Management
hi everyone,
i am stuck in a very weird problem, it looks as if it is impossible.
i have written a function in pgplsql which creates a view in the database. It accepts a parameter of type Varchar. Here is the function definition:
DECLARE
SQL VARCHAR;
BEGIN
SQL = 'CREATE OR REPLACE VIEW Reports.vuReport AS
SELECT *
FROM Reports.plan
WHERE plan_date = ' || $2;
EXECUTE SQL;
RETURN 'Testing';
END;
The name of the function is: tmp and I execute this function like
this: select tmp('2006-11-14');
Now the view is created with the following syntax:
CREATE OR REPLACE VIEW Reports.vuReport AS
SELECT *
FROM Reports.plan
WHERE plan_date::text = (2006 - 11 - 14)::text;
This view does not return me correct values as the date is here text, if i had got this view instead, i get the correct result:
CREATE OR REPLACE VIEW Reports.vuReport AS
SELECT *
FROM Reports.plan
WHERE plan_date = '2006-11-14';
The problem is that, the variable which i am passing does not get quoted. I am not able to find how do i replace 2006-11-14 (without quotes) with '2006-11-14' (with quotes) in my query.
Kindly Help.
Thanx & Regards.
Gaurav
i am stuck in a very weird problem, it looks as if it is impossible.
i have written a function in pgplsql which creates a view in the database. It accepts a parameter of type Varchar. Here is the function definition:
DECLARE
SQL VARCHAR;
BEGIN
SQL = 'CREATE OR REPLACE VIEW Reports.vuReport AS
SELECT *
FROM Reports.plan
WHERE plan_date = ' || $2;
EXECUTE SQL;
RETURN 'Testing';
END;
The name of the function is: tmp and I execute this function like
this: select tmp('2006-11-14');
Now the view is created with the following syntax:
CREATE OR REPLACE VIEW Reports.vuReport AS
SELECT *
FROM Reports.plan
WHERE plan_date::text = (2006 - 11 - 14)::text;
This view does not return me correct values as the date is here text, if i had got this view instead, i get the correct result:
CREATE OR REPLACE VIEW Reports.vuReport AS
SELECT *
FROM Reports.plan
WHERE plan_date = '2006-11-14';
The problem is that, the variable which i am passing does not get quoted. I am not able to find how do i replace 2006-11-14 (without quotes) with '2006-11-14' (with quotes) in my query.
Kindly Help.
Thanx & Regards.
Gaurav