× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



The Table function makes it look like a table to sql, it ends up being equivalent to all the subselects in the other solution proposed but wraps it in a single 'Table' so it is easier and cleaner to code. I don't know if there is any performance difference, you could run Visual Explain on both to see if it ends up being similar. What is inside the 'Table' function does not have to be a function per se, usually for me it is a sql statement. I know how to use it but I don't know if I can explain it well - I have cases where it is just a sql statement that I want to use several columns from at the top level query.

For example (from a Railroad) we have 'Waybills' what have many 'Movement Events'. If I want to find a single Movement Event (based on some logic like first one at a location) and tie it to the waybill the 'Table' function allows this, using a Fetch First Row Only, in a single sql statement. I even use it to find the last 'Movement Event' of a certain type and tie it to a 'Waybill' even if that 'Movement Event' is from another 'Waybill. Hope that is helpful but not sure.

I compare it to 'outer apply' in Sql Server, where I first used it. From my understanding the 'Table' function allows the same functionality in Db2i.

Scott Mildenberger | Software Developer | Washington Corporations | 101 International Drive | Missoula, MT 59808 | Office: (406) 523-1536 | www.washcorp.com

-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Craig Richards
Sent: Tuesday, October 22, 2019 9:06 AM
To: RPG programming on IBM i <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Re: DB2 Services - object_lock_info

Hi Scott,

Thank you very much - that works fine and does seem a lot cleaner.

I'm still struggling to understand exactly what is going on.
Whenever I write SQL, I always try to think of sets of data, what they look like and how they join together.

A LEFT JOIN is straightforward.
But I've not used a Table Function before.

I can see that running something like:

select * from table(users()) u

calls the UDTF users() and returns a table.

I don't really have the mechanics of it clear in my mind as it pertains to the SQL above - as you say, feeding the data though the CTE and also with the join on 1=1 which if I understand it correctly would be some kind of a cross join, which makes me wonder if it's kind of doing a cross join at each row level.

If you have the patience and a bit more free time at some point I would be grateful if you could help me understand the mechanics of exactly what is going on here.

In any case, thanks so much for taking the time to look at my question and provide a helpful and clear solution.
best regards,
Craig


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.