Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wierd Pgplsql Problem

Status
Not open for further replies.

hello2345ji

IS-IT--Management
Dec 22, 2005
1
US
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top