Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 24th, 2011, 12:55 AM
nagysz nagysz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 200 nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 19 m 28 sec
Reputation Power: 13
Convert string to set

Hi,


is there any possibility to use a STRING as SET in Firebird SP?

here's an example:


bill_list='1,2,5,11,27'

select * from bills where id in (:bill_list);

Reply With Quote
  #2  
Old November 24th, 2011, 02:37 AM
mIRCata mIRCata is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Location: Plovdiv. Bulgaria
Posts: 200 mIRCata User rank is Corporal (100 - 500 Reputation Level)mIRCata User rank is Corporal (100 - 500 Reputation Level)mIRCata User rank is Corporal (100 - 500 Reputation Level)mIRCata User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 6 h 50 m 14 sec
Reputation Power: 11
One solution is to use EXECUTE STATEMENT

EXECUTE STATEMENT 'select * from bills where id in (' ||:bill_list ||')';

Another and more complicated is to use global temporary tables. You can insert in one temporary table the ID's you want and execute INNER JOIN with this table:

select bills.* from bills inner join tmp_id on tmp_id.id = bills.id

Just make sure that you've deleted the old values before inserting the new ones if you are going to execute this select many times with different set of IDs in one transaction.
+ With this method you can filter SELECTs with more than 255 values, because IN is limited to accept up to 255 values.
- Firebird creates files on the disk with the data for the temporal table and this can slow the execution of the queries. But you can make a RAM drive for Firebird to use it for its temp files. This also helps for other things that Firebird do if you have enough free RAM.

Last edited by mIRCata : November 24th, 2011 at 02:51 AM.

Reply With Quote
  #3  
Old November 24th, 2011, 04:06 AM
nagysz nagysz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 200 nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level)nagysz User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 11 h 19 m 28 sec
Reputation Power: 13
hi,

thanks a lot for your reply. This global temporary thing aroused my interest.

How can i create global temporary tables? Can i create them inside of an SP? or in the declaration part of an SP?






Quote:
Originally Posted by mIRCata
One solution is to use EXECUTE STATEMENT

EXECUTE STATEMENT 'select * from bills where id in (' ||:bill_list ||')';

Another and more complicated is to use global temporary tables. You can insert in one temporary table the ID's you want and execute INNER JOIN with this table:

select bills.* from bills inner join tmp_id on tmp_id.id = bills.id

Just make sure that you've deleted the old values before inserting the new ones if you are going to execute this select many times with different set of IDs in one transaction.
+ With this method you can filter SELECTs with more than 255 values, because IN is limited to accept up to 255 values.
- Firebird creates files on the disk with the data for the temporal table and this can slow the execution of the queries. But you can make a RAM drive for Firebird to use it for its temp files. This also helps for other things that Firebird do if you have enough free RAM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Convert string to set

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap