|
In regards to your question about nesting functions in an index. They are
allowed but LPAD specifically is not allowed.
Functions not allowed in an index:
ATAN2
CARDINALITY
CONTAINS
CURDATE
CURTIME
DATAPARTITIONNAME
DATAPARTITIONNUM
DAYNAME
DBPARTITIONNAME
DECRYPT_BINARY
DECRYPT_BIT
DECRYPT_CHAR
DECRYPT_DB
DIFFERENCE
DLURLCOMPLETE
DLURLPATH
DLURLPATHONLY
DLURLSCHEME
DLURLSERVER
DLVALUE
ENCRYPT_AES
ENCRYPT_RC2
ENCRYPT_TDES
GENERATE_UNIQUE
GETHINT
IDENTITY_VAL_LOCAL
INSERT
LOCATE_IN_STRING
LPAD
MAX_CARDINALITY
MONTHNAME
MONTHS_BETWEEN
NEXT_DAY
NOW
OVERLAY
RAISE_ERROR
RAND
REGEXP_COUNT
REGEXP_INSTR
REGEXP_REPLACE
REGEXP_SUBSTR
REPEAT
REPLACE
ROUND_TIMESTAMP
RPAD
SCORE
SOUNDEX
TABLE_NAME
TABLE_SCHEMA
TIMESTAMP_FORMAT
TIMESTAMPDIFF
TRUNC_TIMESTAMP
VARCHAR_FORMAT
VERIFY_GROUP_FOR_USER
WEEK_ISO
WRAP
XMLPARSE
XMLVALIDATE
XSLTRANSFORM
Michael Salsman
WinCo Foods, LLC
Programmer
Work: (208) 672-2038
Cell: (208) 949-8665
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf Of
Craig Richards
Sent: Thursday, April 11, 2019 09:38
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: Varchar and numerical sort sequence
Thanks Michael thats good to know.
On Thu, 11 Apr 2019 at 16:13, Salsman, Michael <
Michael.Salsman@xxxxxxxxxxxxxx> wrote:
Craig,https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=3YgXjOrrTgWVExNXH2ijdqnVXpnLzKhXFo6nQeurC9w&s=VLdYB2PtZMODA-cDhmAcoVuE4I4BCFuICcg8SteoZ5U&e=
MySQL has a generated column functionality (without the need for a
trigger).
Another column can be added like follows:
Create table test_table (
Text1 varchar(100),
Text2 varchar(100) as (LPAD(TRIM(Text1),100," "))
)
Then an index can be placed on the Text2 column for ordering.
Michael Salsman
-----Original Message-----
From: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxxxxxxxx] On Behalf
Of Craig Richards
Sent: Thursday, April 11, 2019 05:51
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: Varchar and numerical sort sequence
Hi Birgitta,
Thanks for your reply.
I think I understand what you are saying.
I believe that an index is needed, I think that applying a scalar
function to the ORDER BY column won't be fast enough.
If I understand correctly, your idea is to have a view with the
Right-Adjusted column in it.
And build a Derived Index on the main table which uses the same
expression as the View Column.
I haven''t done anything with derived indices before.
I'm getting an error trying to create one with the nested functions:
e.g:
create index vi on glevarc00
(lpad(trim(evttype), 30) as RAdj)
===Index expression 0 not valid===
I can get it to work for a single function:
create index vi on glevarc00
(trim(evttype) as RAdj) S
I think my syntax is correct in the failing attempt?
thanks and regards,
Craig
On Thu, 11 Apr 2019 at 11:52, Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx>
wrote:
What about using LPAD for right adjusting the content (you don'thttps://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.
have to care where the column includes invalid numeric values or
not) and order the result?
ORDER BY LPAD(Trim(YourCharCol), 15) Desc Fetch 10 Rows only
In either way I'd define a view which includes the an additional
column with the LPAD function.
... you easily can add an ORDER BY over the additional column in
your program.
Additionally I'd create a derived index containing a Key Column
(with the LPAD function).
If the syntax of the view column and the syntax of the Key Column in
the index match, the optimizer can use the index. ...and return the
requested very quick.
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars."
(Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not
training them and keeping them!"
„Train people well enough so they can leave, treat them well enough
so they don't want to.“ (Richard Branson)
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of
Craig Richards
Sent: Donnerstag, 11. April 2019 09:58
To: RPG programming on the IBM i (AS/400 and iSeries)
<rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Varchar and numerical sort sequence
Someone was asking a question on a python board that I subscribe to.
He has a table in a MySQL database which contains a VarChar which
represents a Confirmation Number.
It may be NULL.
And I assume it may contain invalid numerics.
He wants to be able to (for example) retrieve the last 10
Confirmation Numbers based on a numerical sort sequence.
Obviously he can't order by the existing VarChar Confirmation Number
because it's alpha and he will get results like:
901
900
90
899
898
So he has been using CAST to convert the NOT NULL values to INT and
then sorting on that but his response time for the query is very
slow due to the volume of data (and also I think it's part of a
larger
query)
I don't think views will help his cause as you can't use ORDER BY.
My first thought was - can he add another column to the table (over
which he could add a non-unique index) - make it NOT NULLABLE and
default to 0.
Then in the application, modify it when a valid numeric value is
entered in the Confirmation Numer column.
If it's not viable to modify the application - would it make sense
to use an UPDATE TRIGGER to keep the new column maintained.
I don't actually recall having modified the after image in a trigger
program
- is that a reasonable thing to do?
Any advice/comments gratefully accepted.
thanks,
Craig
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post
a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.
co
m_mailman_listinfo_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwol
Pv
SZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7Q
uo
MNhVJ5oau49NIpFT6XgME-QCa3y6vR2w-9kQ&s=249GAqi7faEMcgQQhw47a2_cEsdqw
FO 5DrMjU8n1uwY&e= or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
com_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&
r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7QuoMNhVJ5oau49NIpF
T6XgME-QCa3y6vR2w-9kQ&s=VIu0Vqo_Gem4tRxOQxWshFn-w5D9vE3dAOfAHjFcmms&e=
.
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our
affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange
.c
om&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzG
wg
qZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7QuoMNhVJ5oau49NIpFT6XgME-QCa
3y 6vR2w-9kQ&s=OGP05mvqR5Jt51d7RULQecjltqbuvr7VYg6HzbqlT6o&e=
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post
a message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.
co
m_mailman_listinfo_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwol
Pv
SZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7Q
uo
MNhVJ5oau49NIpFT6XgME-QCa3y6vR2w-9kQ&s=249GAqi7faEMcgQQhw47a2_cEsdqw
FO 5DrMjU8n1uwY&e= or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
com_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&
r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7QuoMNhVJ5oau49NIpF
T6XgME-QCa3y6vR2w-9kQ&s=VIu0Vqo_Gem4tRxOQxWshFn-w5D9vE3dAOfAHjFcmms&e=
.
--
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our
affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange
.c
om&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzG
wg
qZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7QuoMNhVJ5oau49NIpFT6XgME-QCa
3y 6vR2w-9kQ&s=OGP05mvqR5Jt51d7RULQecjltqbuvr7VYg6HzbqlT6o&e=
This is the RPG programming on IBM i (RPG400-L) mailing list To post a
message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.co
m_mailman_listinfo_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPv
SZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7Quo
MNhVJ5oau49NIpFT6XgME-QCa3y6vR2w-9kQ&s=249GAqi7faEMcgQQhw47a2_cEsdqwFO
5DrMjU8n1uwY&e= or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.
com_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&
r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7QuoMNhVJ5oau49NIpF
T6XgME-QCa3y6vR2w-9kQ&s=VIu0Vqo_Gem4tRxOQxWshFn-w5D9vE3dAOfAHjFcmms&e=
.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.c
om&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzGwg
qZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=fYh7QuoMNhVJ5oau49NIpFT6XgME-QCa3y
6vR2w-9kQ&s=OGP05mvqR5Jt51d7RULQecjltqbuvr7VYg6HzbqlT6o&e=
--
This is the RPG programming on IBM i (RPG400-L) mailing list To post a
message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe,
or change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.co
m_mailman_listinfo_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPv
SZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=3YgXjOr
rTgWVExNXH2ijdqnVXpnLzKhXFo6nQeurC9w&s=hfW1jrQnnJQIr4qZYFv5Cyorum0k0mL
i8DQKZmxqHeY&e= or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
.
--
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.c
om&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzGwg
qZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=3YgXjOrrTgWVExNXH2ijdqnVXpnLzKhXFo
6nQeurC9w&s=3EygTWI8r8H3IvxyVEIqo32G4YnEoKiCPsYLklf89kk&e=
This is the RPG programming on IBM i (RPG400-L) mailing list To post a
message email: RPG400-L@xxxxxxxxxxxxxxxxxx To subscribe, unsubscribe, or
change list options,
visit:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.midrange.com_mailman_listinfo_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=3YgXjOrrTgWVExNXH2ijdqnVXpnLzKhXFo6nQeurC9w&s=hfW1jrQnnJQIr4qZYFv5Cyorum0k0mLi8DQKZmxqHeY&e=
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://urldefense.proofpoint.com/v2/url?u=https-3A__archive.midrange.com_rpg400-2Dl&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=3YgXjOrrTgWVExNXH2ijdqnVXpnLzKhXFo6nQeurC9w&s=VLdYB2PtZMODA-cDhmAcoVuE4I4BCFuICcg8SteoZ5U&e=
.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://urldefense.proofpoint.com/v2/url?u=https-3A__amazon.midrange.com&d=DwIGaQ&c=2S-2xx8Cum_thMfWs-kOOHQTwolPvSZ4PFLhr1wDDGs&r=ls1vEGzGwgqZJyzZs7sGJ8CtK97ty2KqTEwuy7Bm0ek&m=3YgXjOrrTgWVExNXH2ijdqnVXpnLzKhXFo6nQeurC9w&s=3EygTWI8r8H3IvxyVEIqo32G4YnEoKiCPsYLklf89kk&e=
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.