Skip to main content
JR Moore
Participating Frequently
Dec 17, 2021 11:41 AM UTC

SQL ODBC TO UNIVERSE LIMIT ROWS

Can someone tell me the proper syntax for SQL statement to Universe. I have a large file that I need to fetch 10000 rows at a time from Universe that will update a remote AZURE DB daily. I don't have control over the AZURE site as EDA seems like a much better solution to keep the remote data current.

I have tried:

SELECT TOP 10000 * FROM FILE;
SELECT * FROM FILE LIMIT 10000;
SELECT * FROM FILE FETCH FIRST 10000;
SELECT * FROM FILE WHERE ROWNUM < 10000;

Thanks JR Moore


------------------------------
JR Moore
IT Special Projects
Rocket Forum Shared Account
Hillsboro US
------------------------------

    21 replies

    JR Moore
    JR MooreAuthor
    Participating Frequently
    Dec 23, 2021 2:31 PM UTC
    After reading through this thread, I'm guessing that you don't always want just the first 10K records, you are looking to 'chunk' the file.

    To achieve that, you'll also need an offset/skip.

    I'm not sure about Universe (couldn't find the reference guide to check), but this isn't directly supported in AQL on D3.  However; if you save the results to a list first, you can do the following:

    execute "sselect file";
    execute "save-list listname";
    
    *first 10K
    execute "get-list listname (1-10000)"
    
    *next 10K
    execute "get-list listname (10001-20000)"​


    The overhead of having to select and save the list beforehand is not optimal, but I'm not aware of any ... SAMPLING {N} SKIP {N} - which would be a really nice addition.

    Hope this helps.

    Jeremy



    ------------------------------
    Jeremy Lockwood
    Awesome
    ASE Supply Inc
    Portland OR US
    ------------------------------
    Jeremy:

    Thanks for the reply! When I retrieve the records I'm updating a control record and putting a date in the record that I sent the record. Then I select the records without the date from a sorted savedlist. Now I'm getting another error when calling the program.

    Program "SQL_CALL_LIMIT_COMN": Line 26, FATAL: the locks necessary for database operations at the current isolation level (1) are not held by this process.
    line26 = " WRITE DATE() ON F.CONTROL,'RECORD'

    It seems to be a permissions issue with the ODBC user. If I run the same CALL in the ODBC tester with the same credentials used in my external Python program the CALL works?

    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    Neil Morris
    Rocketeer
    Dec 23, 2021 4:30 PM UTC
    Jeremy:

    Thanks for the reply! When I retrieve the records I'm updating a control record and putting a date in the record that I sent the record. Then I select the records without the date from a sorted savedlist. Now I'm getting another error when calling the program.

    Program "SQL_CALL_LIMIT_COMN": Line 26, FATAL: the locks necessary for database operations at the current isolation level (1) are not held by this process.
    line26 = " WRITE DATE() ON F.CONTROL,'RECORD'

    It seems to be a permissions issue with the ODBC user. If I run the same CALL in the ODBC tester with the same credentials used in my external Python program the CALL works?

    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    Does the program perform a READU on F.CONTROL,'RECORD' before doing the WRITE? It would appear the WRITE is happening within a transaction and it expects a lock to be set on the record prior to the WRITE operation. The error indicates a lock is not set.

    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    JR Moore
    JR MooreAuthor
    Participating Frequently
    Jan 3, 2022 6:24 PM UTC
    Does the program perform a READU on F.CONTROL,'RECORD' before doing the WRITE? It would appear the WRITE is happening within a transaction and it expects a lock to be set on the record prior to the WRITE operation. The error indicates a lock is not set.

    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    Neil:

    Thanks for the reply I'm still having lock issues on the control file. My code is below as you can see I added a READU and a RELEASE not sure why it is not working.

    OPEN 'CONTROL' TO F.CONTROL ELSE CONTROL.OPEN = 0
    OPEN 'EPWCOMNINVMSPF' TO F.EPW ELSE STOP
    *
    * pull in the last date
    *

    READU DATEREC FROM F.CONTROL, 'LAST.DATE.REC' THEN
    LAST.DATE = DATEREC<1>
    END ELSE
    LAST.DATE = ""
    END
    THIS.TIME = TIME()
    *
    * if running this for the first time today, create a save list in NI order
    *
    IF LAST.DATE # DATE() THEN
          DATEREC<1> = DATE()
          DATEREC<2> = THIS.TIME
          DATEREC<3> = ""
          DATEREC<4> = ""
          WRITE DATEREC ON F.CONTROL,'LAST.DATE.REC'
          RELEASE F.CONTROL,'LAST.DATE.REC'

    Below is the lock that is set
    Active Record Locks:
    Device.... Inode.... Netnode Userno Lmode Pid Login Id Item-ID........

    64771 139239659 0 -6 37 RU 22294 root LAST.DATE.REC

    Below is the calling python program
    conn = pyodbc.connect('DSN=dsn;UID=user;PWD=pass')
        cursor = conn.cursor()
        stmt = "CALL SQL_CALL_LIMIT_COMN LIMIT 10000"

    Thanks JR Moore


    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    JR Moore
    JR MooreAuthor
    Participating Frequently
    Jan 3, 2022 6:32 PM UTC
    Neil:

    Thanks for the reply I'm still having lock issues on the control file. My code is below as you can see I added a READU and a RELEASE not sure why it is not working.

    OPEN 'CONTROL' TO F.CONTROL ELSE CONTROL.OPEN = 0
    OPEN 'EPWCOMNINVMSPF' TO F.EPW ELSE STOP
    *
    * pull in the last date
    *

    READU DATEREC FROM F.CONTROL, 'LAST.DATE.REC' THEN
    LAST.DATE = DATEREC<1>
    END ELSE
    LAST.DATE = ""
    END
    THIS.TIME = TIME()
    *
    * if running this for the first time today, create a save list in NI order
    *
    IF LAST.DATE # DATE() THEN
          DATEREC<1> = DATE()
          DATEREC<2> = THIS.TIME
          DATEREC<3> = ""
          DATEREC<4> = ""
          WRITE DATEREC ON F.CONTROL,'LAST.DATE.REC'
          RELEASE F.CONTROL,'LAST.DATE.REC'

    Below is the lock that is set
    Active Record Locks:
    Device.... Inode.... Netnode Userno Lmode Pid Login Id Item-ID........

    64771 139239659 0 -6 37 RU 22294 root LAST.DATE.REC

    Below is the calling python program
    conn = pyodbc.connect('DSN=dsn;UID=user;PWD=pass')
        cursor = conn.cursor()
        stmt = "CALL SQL_CALL_LIMIT_COMN LIMIT 10000"

    Thanks JR Moore


    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    Added detail:
    If I run it on the database it works so it has to be some sort of permission related to the ODBC. I have tried the python as my userid and also as root same result lock set on the CONTROL file. The CONTROl file has rwx-rwx-rwx Linux permissions.

    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    Mike Rajkowski
    Rocketeer
    Jan 4, 2022 8:18 AM UTC
    Added detail:
    If I run it on the database it works so it has to be some sort of permission related to the ODBC. I have tried the python as my userid and also as root same result lock set on the CONTROL file. The CONTROl file has rwx-rwx-rwx Linux permissions.

    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    JR,

    How do you release the lock if the LAST.DATE = DATE()? 

    Have you tried putting the RELEASE command outside of the IF...THEN...ELSE statements. 


    ------------------------------
    Mike Rajkowski
    support
    Rocket Internal - All Brands
    DENVER CO US
    ------------------------------
    Neil Morris
    Rocketeer
    Jan 4, 2022 8:29 AM UTC
    Added detail:
    If I run it on the database it works so it has to be some sort of permission related to the ODBC. I have tried the python as my userid and also as root same result lock set on the CONTROL file. The CONTROl file has rwx-rwx-rwx Linux permissions.

    ------------------------------
    JR Moore
    IT Special Projects
    Rocket Forum Shared Account
    Hillsboro US
    ------------------------------
    Hi JR,
    Based on your last update, I wasn't sure if you were getting the same error or was there now a new error? The suggestion of adding the READU was to eliminate the "locks necessary for database...." error. Is that still happening? Or is there a new error after adding the READU?
    Thanks,
    Neil

    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    JR Moore
    JR MooreAuthor
    Participating Frequently
    Jan 4, 2022 9:51 AM UTC
    Hi JR,
    Based on your last update, I wasn't sure if you were getting the same error or was there now a new error? The suggestion of adding the READU was to eliminate the "locks necessary for database...." error. Is that still happening? Or is there a new error after adding the READU?
    Thanks,
    Neil

    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    Neil:

    No I'm not getting the error now it appears to be hanging at the lock and does not produce any data. 

    Thanks JR Moore

    ------------------------------
    JR Moore
    IT Special Projects
    Auto Parts Warehouse
    Hillsboro US
    ------------------------------
    JR Moore
    JR MooreAuthor
    Participating Frequently
    Jan 4, 2022 10:03 AM UTC
    JR,

    How do you release the lock if the LAST.DATE = DATE()? 

    Have you tried putting the RELEASE command outside of the IF...THEN...ELSE statements. 


    ------------------------------
    Mike Rajkowski
    support
    Rocket Internal - All Brands
    DENVER CO US
    ------------------------------
    Mike:

    Thanks for the reply. I added a release outside of the IF statement and no change. It will run locally so the lock that is being sent seems to be unrelated to the format of the conditional statement. The issue seems to be with the program being run from ODBC and not from TCL.

    Thanks JR Moore

    ------------------------------
    JR Moore
    IT Special Projects
    Auto Parts Warehouse
    Hillsboro US
    ------------------------------
    Neil Morris
    Rocketeer
    Feb 1, 2022 3:02 PM UTC
    Neil:

    No I'm not getting the error now it appears to be hanging at the lock and does not produce any data. 

    Thanks JR Moore

    ------------------------------
    JR Moore
    IT Special Projects
    Auto Parts Warehouse
    Hillsboro US
    ------------------------------
    Hi JR,
    This thread fell off the radar. Are you still encountering issues?
    If the process is hanging, have you checked the LIST.READU EVERY output on the server to see if you can identify locks which might be blocking?
    At the same time, you could try running PORT.STATUS PID {pid of hung process} LAYER.STACK to see if that identified where the process is currently stuck.
    Thanks,
    Neil

    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    JR Moore
    JR MooreAuthor
    Participating Frequently
    Feb 2, 2022 12:48 PM UTC
    Hi JR,
    This thread fell off the radar. Are you still encountering issues?
    If the process is hanging, have you checked the LIST.READU EVERY output on the server to see if you can identify locks which might be blocking?
    At the same time, you could try running PORT.STATUS PID {pid of hung process} LAYER.STACK to see if that identified where the process is currently stuck.
    Thanks,
    Neil

    ------------------------------
    Neil Morris
    Universe Advanced Technical Support
    Rocket Software
    ------------------------------
    Neil:

    Thanks for the inquiry! Not sure why it would hang when I called it VIA a python program. I wrote a PHP program to do the same function and it worked fine??? I was pyodbc to get the data from Universe maybe there was a row limit with the call not sure. If I kept it under 2500 records it would work over that create the locks on Universe.

    ------------------------------
    Jr Moore
    IT Special Projects
    Auto Parts Warehouse
    Hillsboro US
    ------------------------------