Maximum length of the SQL-statment

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GVCL
Posts: 17
Joined: Tue 09 Dec 2008 16:08

Maximum length of the SQL-statment

Post by GVCL » Thu 23 Oct 2014 16:09

Hi,

how long in characters can a SQL-statement be using IBDAC components? I could not find any restrictions mentioned somewhere, but I am sure there are some :wink:

I want to use a SELECT * FROM ANYTAB WHERE ANYID IN (100,234,345...) with may be hundreds or even thousands of items. Would that be possible?

A BETWEEN or similar would not work as i.e. the IDs are randomly distributed and are not sequential.

Any hint welcome!

abak
Posts: 29
Joined: Sat 18 Oct 2014 18:42

Re: Maximum length of the SQL-statment

Post by abak » Thu 23 Oct 2014 21:34

Hi GVCL,

Don't use "in" statment in your select query : depreciated and slow !
You can get around by :
- creating a second table Table2
- insert your thounsand ID in this table
- then, join it to your table :
_______________________________________________
Select T1.field1, T1.field2, ...
From myTable T1 Join Table2 T2 on T1.ID = T2.ID
_______________________________________________

The Table2 has 2 fields : its autoincrement key ID2 and your field ID (wanted)
ID2 ID
1 185
2 983
3 1097

And to go fast, you can create an index for the ID field in table2 :
CREATE [ASC[ENDING] | [DESC[ENDING]] INDEX indexname
ON table2 ID

Best regards.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Maximum length of the SQL-statment

Post by ViktorV » Fri 24 Oct 2014 08:16

Firebird applies a limit of 64KB (65536 characters in a single-byte character set) to the SQL statement.

Post Reply