Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > BROBLEM IN BETW...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 3387 of 3558
Post > Topic >>

BROBLEM IN BETWEEN QUERY (plpgsql)

by anoopmadavoor@[EMAIL PROTECTED] ("Anoop G") Apr 3, 2008 at 03:54 PM

------=_Part_641_9553234.1207218296825
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

hai all,

    I have  a  plpgsql function and I am using   postgresl 8.1.9


CREATE OR REPLACE FUNCTION get_vehicle_id(INT) RETURNS SETOF RECORD AS
$BODY$
DECLARE

    r RECORD;
        int_day  ALIAS FOR $1;

BEGIN

     FOR r in SELECT fk_bint_old_vehicle_number AS vehicle_id
     FROM tbl_rac_vehicle_replacement
     WHERE dat_replacement BETWEEN now() - interval '% day',int_day
     AND now() LOOP

             RETURN NEXT r;
     END LOOP;

     RETURN;
END
$BODY$ LANGUAGE 'plpgsql';


   But i cant craete the function  The error message is:


ERROR:  syntax error at or near "," at character 137
QUERY:   SELECT fk_bint_old_vehicle_number AS vehicle_id FROM
tbl_rac_vehicle_replacement WHERE dat_replacement BETWEEN now() - interval
'% day', $1  AND now()
CONTEXT:  SQL statement in PL/PgSQL function "test" near line 11
LINE 1: ...E dat_replacement BETWEEN now() - interval '% day', $1  AND ...




The problem line is  BETWEEN now() - interval '% day', $1  AND now()

I want to select  dat_replacement  between now ()  and now - 5 dyas or now
-7 days like that  i want to pass the integer value as argument to the
function.


I also tried like this  WHERE dat_replacement BETWEEN now() - interval
int_day day
     AND now(),but it also failed.


     Please help me .

  regards:
              Anoop

------=_Part_641_9553234.1207218296825
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

hai all,<br><br>&nbsp;&nbsp;&nbsp; I have&nbsp; a&nbsp; plpgsql function
and I am using&nbsp;&nbsp; postgresl 8.1.9<br><br><br>CREATE OR REPLACE
FUNCTION get_vehicle_id(INT) RETURNS SETOF RECORD AS
$BODY$<br>DECLARE<br><br>&nbsp;&nbsp;&nbsp; r
RECORD;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int_day&nbsp; ALIAS
FOR $1;<br>
<br>BEGIN<br><br>&nbsp;&nbsp;&nbsp;&nbsp; FOR r in SELECT
fk_bint_old_vehicle_number AS vehicle_id<br>&nbsp;&nbsp;&nbsp;&nbsp; FROM
tbl_rac_vehicle_replacement<br>&nbsp;&nbsp;&nbsp;&nbsp; WHERE
dat_replacement BETWEEN now() - interval &#39;% day&#39;,int_day
<br>&nbsp;&nbsp;&nbsp;&nbsp; AND now() LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
RETURN NEXT r;<br>&nbsp;&nbsp;&nbsp;&nbsp; END
LOOP;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;
RETURN;<br>END<br>$BODY$ LANGUAGE
&#39;plpgsql&#39;;<br><br><br>&nbsp;&nbsp; But i cant craete the
function&nbsp; The error message is:<br><br><br>ERROR:&nbsp; syntax error
at or near &quot;,&quot; at character 137<br>
QUERY:&nbsp;&nbsp; SELECT fk_bint_old_vehicle_number AS vehicle_id FROM
tbl_rac_vehicle_replacement WHERE dat_replacement BETWEEN now() - interval
&#39;% day&#39;, $1&nbsp; AND now()<br>CONTEXT:&nbsp; SQL statement in
PL/PgSQL function &quot;test&quot; near line 11<br>
LINE 1: ...E dat_replacement BETWEEN now() - interval &#39;% day&#39;,
$1&nbsp; AND ...<br><br><br><br><br>The problem line is&nbsp;  BETWEEN
now() - interval &#39;% day&#39;, $1&nbsp; AND now()<br><br>I want to
select&nbsp; dat_replacement&nbsp; between now ()&nbsp; and now - 5 dyas
or now -7 days like that&nbsp; i want to pass the integer value as
argument to the function.<br>
<br><br>I also tried like this&nbsp; WHERE dat_replacement BETWEEN now() -
interval int_day day <br>&nbsp;&nbsp;&nbsp;&nbsp; AND now(),but it also
failed.<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp; Please help me .<br><br>&nbsp;
regards:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Anoop<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
<br><br><br><br><br>&nbsp;&nbsp;&nbsp; <br><br>&nbsp;&nbsp;
<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>

------=_Part_641_9553234.1207218296825--




 2 Posts in Topic:
BROBLEM IN BETWEEN QUERY (plpgsql)
anoopmadavoor@[EMAIL PROT  2008-04-03 15:54:56 
Re: BROBLEM IN BETWEEN QUERY (plpgsql)
andreas.kretschmer@[EMAIL  2008-04-03 13:09:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan13V112 Fri Jul 4 23:06:00 CDT 2008.