Обсуждение: how to perform minus (-) operation in a dynamic query

Поиск
Список
Период
Сортировка

how to perform minus (-) operation in a dynamic query

От
"Anoop G"
Дата:

Hai all,

I am new to plpgsql ,I have a  table  structure:

 Column |       Type       | Modifiers
--------+------------------+-----------
 mf     | double precision |
 sf     | double precision |
 comm   | integer          |

I create a  the following funtion

create or replace function test_perc() returns setof record as $body$

declare

vchr_query VARCHAR(100);

r record;

begin

vchr_query:= 'SELECT mf,sf,(mf – mf * comm /100) – (sf – sf * comm/100) as flt_claim';

FOR r in EXECUTE vchr_query LOOP

RETURN NEXT r;

END LOOP;

RETURN;

end$body$
language 'plpgsql'


function created

but when I am traing to run this function I got the following error

ERROR:  syntax error at or near "–" at character 18
QUERY:  SELECT mf,sf,(mf – mf * comm /100) – (sf – sf * comm/100) as flt_claim
CONTEXT:  PL/pgSQL function "test_perc" line 7 at for over execute statement
LINE 1: SELECT mf,sf,(mf – mf * comm /100) – (sf – sf * comm/100) as...

How I can solve this ,pls help me


thanks in advance:
Anoop



Re: how to perform minus (-) operation in a dynamic query

От
"A. Kretschmer"
Дата:
am  Mon, dem 14.07.2008, um 11:21:17 +0530 mailte Anoop G folgendes:
> SELECT mf,sf,(mf   mf * comm /100)   (sf   sf * comm/100) as flt_claim;                 ^^^               ^^^   ^^^

That's not valid SQL.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


Re: how to perform minus (-) operation in a dynamic query

От
Markus Wanner
Дата:
Hi,

Anoop G wrote:
> vchr_query:= 'SELECT mf,sf,(mf – mf * comm /100) – (sf – sf * comm/100) 
> as flt_claim';

Simply use a real minus sign '-', and not a hyphen '–'. (Try 
copy'n'pasting from this email, if nothing else works ;-) )

Regards

Markus



Re: how to perform minus (-) operation in a dynamic query

От
Tom Lane
Дата:
"Anoop G" <anoopmadavoor@gmail.com> writes:
> ERROR:  syntax error at or near "\226" at character 18
> QUERY:  SELECT mf,sf,(mf \226 mf * comm /100) \226 (sf \226 sf * comm/100) as
> flt_claim
> CONTEXT:  PL/pgSQL function "test_perc" line 7 at for over execute statement
> LINE 1: SELECT mf,sf,(mf \226 mf * comm /100) \226 (sf \226 sf * comm/100) as...

I'm not sure what character \226 is, but it's not a minus sign ...
        regards, tom lane


Re: how to perform minus (-) operation in a dynamic query

От
"Anoop G"
Дата:
Hai all,

 Thanks to all , I got the answer,  actualy I am write the function in openoffice.org and paste it to a .sql file that is the reason for the error.

thanks
Anoop









On Mon, Jul 14, 2008 at 7:32 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
"Anoop G" <anoopmadavoor@gmail.com> writes:
> ERROR:  syntax error at or near "\226" at character 18
> QUERY:  SELECT mf,sf,(mf \226 mf * comm /100) \226 (sf \226 sf * comm/100) as
> flt_claim
> CONTEXT:  PL/pgSQL function "test_perc" line 7 at for over execute statement
> LINE 1: SELECT mf,sf,(mf \226 mf * comm /100) \226 (sf \226 sf * comm/100) as...

I'm not sure what character \226 is, but it's not a minus sign ...

                       regards, tom lane