473,414 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

how to append the string to SQL queries in stored procedure of Postgres....

i want to append the string which is present in the stored pocedure to SQL query

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key==b.key';

for s in

select * from tbl_text1 a,tbl_test2 b where a.id==b.id and (want to append string tempapp here);

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';


can you help me regarding this..............its urgent

Regards
Shree
Dec 11 '07 #1
9 21848
rski
700 Expert 512MB
i want to append the string which is present in the stored pocedure to SQL query

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key==b.key';

for s in

select * from tbl_text1 a,tbl_test2 b where a.id==b.id and (want to append string tempapp here);

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';


can you help me regarding this..............its urgent

Regards
Shree
Do it with execute

EXECUTE 'select * from tbl_text1 a,tbl_test2 b where a.id==b.id and '||tempapp;
I'm not sure if it works without EXECUTE
Dec 11 '07 #2
Do it with execute

EXECUTE 'select * from tbl_text1 a,tbl_test2 b where a.id==b.id and '||tempapp;
I'm not sure if it works without EXECUTE

i didnt get result...but i have found an alternative way.....i have taken remaining query in a string variable and appended tht variable as u told...now its working...thanks.....

i have got another problem....want to take first parameter in a string variable and append that string in the execute query....its like follow---------

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key==$1'; (its showing error here)
squery:='select * from tbl_text1 a,tbl_test2 b where '

for s in

execute squery || tempapp

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';

$1 value is not taking inside execute statement....can u help me out regarding this problem...its urgent
Regards
Shree
Dec 12 '07 #3
rski
700 Expert 512MB
i didnt get result...but i have found an alternative way.....i have taken remaining query in a string variable and appended tht variable as u told...now its working...thanks.....

i have got another problem....want to take first parameter in a string variable and append that string in the execute query....its like follow---------

CREATE OR REPLACE FUNCTION sample(fid varchar,ioffset int)
RETURNS SETOF totaltype AS $$
DECLARE

s totaltype %ROWTYPE;


SQL_Tx_Type VARCHAR(4000);
SQL_User_Count VARCHAR(4000);

BEGIN

tempapp:='a.key==$1'; (its showing error here)
squery:='select * from tbl_text1 a,tbl_test2 b where '

for s in

execute squery || tempapp

loop

return next s;
end loop;

end
$$ LANGUAGE 'plpgsql';

$1 value is not taking inside execute statement....can u help me out regarding this problem...its urgent
Regards
Shree
maybe like this
tempapp:='a.key=='||$1
doesn't it work ?
If no what is the error message
Dec 12 '07 #4
maybe like this
tempapp:='a.key=='||$1
doesn't it work ?
If no what is the error message

hey,thanks....i have got the result..... :)


got one more problem------------------

i have declared a string variable with some value,i want to check whether that string ends with "and" ....

how to do it in stored procedure----its like this

CREATE OR REPLACE FUNCTION test()
RETURNS varchar AS $$


DECLARE
samp varchar(400)
wr varchar;
index1 int;
begin
wr:='';
samp:=' (select * from tbl_usertable where a.ecpclaim_carrier_id ILIKE
''PAPER'' and '

IF (samp.endsWith(''and'')) then

index1:=samp.lastIndexOf(''and'');
samp:=samp.replace(index,length(samp),'''');
end if;

IF (samp IS NULL) then
samp:=samp || wr;
end if;

return
end
$$ LANGUAGE 'plpgsql';

its showing error in "endsWith" and "lastIndexOf", so what are the functions we have to use in stored procedure of postgre for the functions "endsWith" and "lastIndexOf"???????

help me out plz.........

Regards
Shree
Dec 13 '07 #5
rski
700 Expert 512MB
hey,thanks....i have got the result..... :)


got one more problem------------------

i have declared a string variable with some value,i want to check whether that string ends with "and" ....

how to do it in stored procedure----its like this

CREATE OR REPLACE FUNCTION test()
RETURNS varchar AS $$


DECLARE
samp varchar(400)
wr varchar;
index1 int;
begin
wr:='';
samp:=' (select * from tbl_usertable where a.ecpclaim_carrier_id ILIKE
''PAPER'' and '

IF (samp.endsWith(''and'')) then

index1:=samp.lastIndexOf(''and'');
samp:=samp.replace(index,length(samp),'''');
end if;

IF (samp IS NULL) then
samp:=samp || wr;
end if;

return
end
$$ LANGUAGE 'plpgsql';

its showing error in "endsWith" and "lastIndexOf", so what are the functions we have to use in stored procedure of postgre for the functions "endsWith" and "lastIndexOf"???????

help me out plz.........

Regards
Shree
I think position() function might help, but for more info see here
http://www.postgresql.org/docs/8.2/i...ns-string.html
Dec 13 '07 #6
I think position() function might help, but for more info see here
http://www.postgresql.org/docs/8.2/i...ns-string.html

ya,got the result..thanks a lot.......

got one more issue.....

how to check case for a string in stored procedure....

i want to use equalsIgnoreCase().....i thinks this string function is not available in postgreSQL....so how can i check case for string here......give me the syntax plz

Regards
Shree
Dec 14 '07 #7
rski
700 Expert 512MB
ya,got the result..thanks a lot.......

got one more issue.....

how to check case for a string in stored procedure....

i want to use equalsIgnoreCase().....i thinks this string function is not available in postgreSQL....so how can i check case for string here......give me the syntax plz

Regards
Shree
I'm not suer if understand whatvyou want, but if you want to compare strings without case senstitive ins SQL queries you can use ILIKE operator, or you can user upper() or lower() functions.
Dec 14 '07 #8
I'm not suer if understand whatvyou want, but if you want to compare strings without case senstitive ins SQL queries you can use ILIKE operator, or you can user upper() or lower() functions.

Acually,i want to check the condition like this.......

if((sReceiverType IS NOT NULL) AND (sReceiverType='paper')) then

-----------some statement here---------

end if;


if input of "sReceiverType" is 'PAPER' then this condition will be false...

so,i want to ingnore case.......

which is like this in java class-------
sReceiverType.equalsIgnoreCase("paper");

so,what string function we have to use to do the same.....???????


thanks and Regards
Shree
Dec 15 '07 #9
rski
700 Expert 512MB
Acually,i want to check the condition like this.......

if((sReceiverType IS NOT NULL) AND (sReceiverType='paper')) then

-----------some statement here---------

end if;


if input of "sReceiverType" is 'PAPER' then this condition will be false...

so,i want to ingnore case.......

which is like this in java class-------
sReceiverType.equalsIgnoreCase("paper");

so,what string function we have to use to do the same.....???????


thanks and Regards
Shree
Maybe like this (it's the simples solution)
if((sReceiverType IS NOT NULL) AND (lower(sReceiverType)='paper')) then
Dec 15 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: mmm, Pie | last post by:
I never ever thought about this, but recently I made a query in access so I can make a customer mailing list based on relational information and it was so easy to make the query and join tables and...
2
by: Satvic | last post by:
Hi all, Sorry for HTML, there is a lot of code & comments I tried to create a stored procedure from 3 queries .. to reduce # of times DB gets access from 1 asp page. The result procedure only...
8
by: Mike N. | last post by:
Hello: I am new to T-SQL programing, and relativly new to SQL statements in general, although I have a good understanding of database theory. I'm a little confused as to the fundamental...
3
by: WGW | last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost! everything I need. Maybe not efficiently, but usefully. However, I have a problem -- a complex query problem... I can...
13
by: Anton.Nikiforov | last post by:
Hello everybody! Does someone know how to build hierarchical queries to the postgresql? I have a table with tree in it (id, parent) and need to find a way from any point of the tree to any...
3
by: Zlatko | last post by:
A question concerning Access Project with SQL Server: I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are...
2
by: rooster575 | last post by:
Im running a querystring in vb.net and it seems as though SQL server decides on the order in which to run the 3 queries in the string.. Is this possible? I would think that SQL server starts with...
0
by: audleman | last post by:
I have an ASP form on my website where a visitor enters information. On submit, the form calls a stored procedure stores in a MS SQL 2000 database. The stored procedure works most of the time, but...
4
by: enginious | last post by:
Hi, I'm sure I'm asking a very easy question, but I am currently in the process of migrating from MS SQL to PostgreSQL and I am facing a few issues, which I would appreciate your help/advice on :...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.