What is the cause of using SELECT null FROM RDB$DATABASE

Asked

Viewed 690 times

4

I don’t understand this SELECT null FROM RDB$DATABASE:

SELECT CK.IDCHEK,
       CK.DESCHE,
       (SELECT null FROM RDB$DATABASE) AS ENTEGU
FROM TC_CHECKL CK
ORDER BY CK.IDCHEK

It looks like it goes in an internal bank table and brings nothing. Later in the code the programmer is saving it with Insert direct on the bench at the event onDraw.

2 answers

1

Not at first, none. When it comes to SQL, taking into account the versions 2.0 from Firebird, the code you showed is no better than the code below:

SELECT CK.IDCHEK,
       CK.DESCHE,
       null AS ENTEGU
FROM TC_CHECKL CK
ORDER BY CK.IDCHEK

I searched for possible bugs in Firebird, but I couldn’t find any related to the query. So, besides possible error of the programmer who made SQL, I believe that two things could be the causes:

1) Due to compatibility with the components used in Delphi. Perhaps using the SQL of my answer, the components detect the ENTEGU field as if it were of a different type (float or string) to the current SQL.

2) Select was more complicated, using other fields, but it was optimized. To avoid possible errors, the programmer kept the (SELECT null FROM RDB$DATABASE).

  • 1

    Embarrassment is correct, there is no reason to use it. If we try to think of reasons for this, the guy who made this sql might use this selection as a substitution point. Example: At runtime, by means of a Stringreplace, it might exchange null for a given field and rdb$database for a table. This in this context would create the possibility to define at runtime where the value of the field would come from. The very use of this process within an 'onDraw' reveals a certain degree of inexperience of the guy, because this event is not appropriate to open queryes not by far

  • I am being denied without explanation here. But I firmly believe that the answer is correct. If you wish you can show me where I am wrong.

-1

This is a way to execute queries that return only one record. I don’t think Firebird has TOP 1 support. Here are some examples: http://www.tecnobyte.com.br/dica9.html?pagina=dica9.html

If the current version allows queries that return only one record without using the above form, it may be worth refactoring in the name of clarity.

  • Would it be to give a TOP 1 in subquery? Why not use NULL AS ENTEGU directly?

  • From what I understand, this makes the query return only one result (the first according to the ORDER). If it included NULL, it would return all records with the value of the third column as NULL

  • TOP has nothing to do with the case. Firebird accepts the clause so much FIRST x SKIP y, as ROWS which is aimed at limiting the number of records shown.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.