Why check for ? on a char field

Posted by Venky on 05-Jun-2015 04:14

Is there any real reason why we have to do this

for each customer where city <> "" and city <> ? no-lock:

And why is there no data type compatibility error when checking character field against ?.

Thanks,

Venky 

Posted by Swathi Yellavaram on 05-Jun-2015 04:40

The special character ? (without quotes) is treated as unknown in ABL language. More information about this you can find here:

documentation.progress.com/.../index.html

Thanks,

Swathi.

All Replies

Posted by Swathi Yellavaram on 05-Jun-2015 04:40

The special character ? (without quotes) is treated as unknown in ABL language. More information about this you can find here:

documentation.progress.com/.../index.html

Thanks,

Swathi.

Posted by Stefan Drissen on 05-Jun-2015 05:12

And since nothing is 'less' than an empty string, I will always use:

city > ""

Posted by ke@iap.de on 05-Jun-2015 05:20

Note:

Normally your application (or DB trigger, constraint) will make sure, there is no ? in the DB in char fields. So code the ? in all queries is kind of paranoia and not helpful in question of clearness and performance.

Posted by Stefan Drissen on 05-Jun-2015 05:29

Why? There is a nice differentiation between 'I do not know the city (yet)' and 'I know there is no city' (which may be a bit strange in the case of an address with a city, but can apply for other fields).

On the performance side a > "" will be able to bracket on an index, whereas <> will not.

Posted by George Potemkin on 05-Jun-2015 05:49

> And since nothing is 'less' than an empty string,

It was not true in old Progress versions:

www.peg.com/.../msg00537.html

> On the performance side a > "" will be able to bracket on an index, whereas <> will not.

Formally it's a bracketing but in fact it's still a full table scan. The only difference between "<>" and ">" in this case - "<>" will use a primary index while ">" will use an index on the "city" field.

Posted by Simon L. Prinsloo on 05-Jun-2015 07:11

[quote user="Stefan Drissen"]

And since nothing is 'less' than an empty string, I will always use:

city > ""

[/quote]

This can catch you off guard. If city is not indexed, it will select only records with cities and ignore those that are blank or ?.

But ? sorts high in an index, so if city is indexed, the lack of an upper bound causes the bracket to be on the city index, from "greater than blank" to the end of the index, which includes the records containing ?, thus the records with ? will be returned as well.

You can easily see the difference if you run the following example with and without the index definition on the temp-table.

DEFINE TEMP-TABLE tt 
   FIELD cf AS CHARACTER
   /*INDEX idx cf*/
   .
   
   
CREATE tt.
ASSIGN cf = "Koos".
CREATE tt.
ASSIGN cf = "Jan".

CREATE tt.
ASSIGN cf = ?.

FOR EACH tt WHERE cf > "":
   DISPLAY tt.
END.


This is well documented in the documentation, specifically in "OpenEdge Web Paper: ABL Database Triggers and Indexes" under the heading "Indexes and unknown values".

Posted by Peter Judge on 05-Jun-2015 07:29


[quote ]

This is well documented in the documentation, specifically in "OpenEdge Web Paper: ABL Database Triggers and Indexes" under the heading "Indexes and unknown values".

[/quote ]
 
 
Mike Lonski also does an excellent talk on this, especially as it pertains to temp-tables – see last year's at the PUG Challenge US (374: You still don't know enough about indices — Mike Lonski, Allegro Consultants, LTD at http://pugchallenge.org/downloads2014.html ).
 
Speaking of PUG Challenge, I'm looking forward to seeing everyone there again.
 
-- peter
 
[collapse]
From: Simon L. Prinsloo [mailto:bounce-simonvidisolvecom@community.progress.com]
Sent: Friday, 05 June, 2015 08:12
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Why check for ? on a char field
 
Reply by Simon L. Prinsloo
Stefan Drissen
And since nothing is 'less' than an empty string, I will always use:
city > ""

This can catch you off guard. If city is not indexed, it will select only records with cities and ignore those that are blank or ?.

But ? sorts high in an index, so if city is indexed, the lack of an upper bound causes the bracket to be on the city index, from "greater than blank" to the end of the index, which includes the records containing ?, thus the records with ? will be returned as well.

You can easily see the difference if you run the following example with and without the index definition on the temp-table.

DEFINE TEMP-TABLE tt 
   FIELD cf AS CHARACTER
   /*INDEX idx cf*/
   .
   
   
CREATE tt.
ASSIGN cf = "Koos".
CREATE tt.
ASSIGN cf = "Jan".
 
CREATE tt.
ASSIGN cf = ?.
 
FOR EACH tt WHERE cf > "":
   DISPLAY tt.
END.


This is well documented in the documentation, specifically in "OpenEdge Web Paper: ABL Database Triggers and Indexes" under the heading "Indexes and unknown values".

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Stefan Drissen on 05-Jun-2015 08:24

Hmm... very interesting. I have to admit to usually only using > "" in IF statements - but will need to perform a quick query scan...

Posted by Richard.Kelters on 07-Jun-2015 14:09

To prevent unknown values in DB you can define a field as mandatory.

This thread is closed