Search code examples
oracle-databasejoinnetezzacross-join

Convert Oracle (Cross Join?) to Netezza when using comma separated table list instead of JOIN keywords


Below is is some Oracle PL/SQL code to join tables without using actual JOIN keywords. This looks like a cross join? How would I convert to Netezza SQL code? That's where I'm stuck.

SELECT COUNT(*) 
FROM TABLE_A A, TABLE_A B
WHERE A.X = 'Y' AND A.PATH LIKE '/A/A/A'
AND B.X = 'Z' AND B.PATH LIKE '/B/B/B';

Oracle Cross Join:

http://www.sqlguides.com/sql_cross_join.php

Here's what I tried so far:

SELECT *
from TABLE_A A
cross join (
    select * from TABLE_A
) B
WHERE 
  A.X = 'Y' AND A.PATH LIKE '/A/A/A'
  AND B.X = 'Z' AND B.PATH LIKE '/B/B/B';

EDIT:

a_horse_with_no_name:

When I use either syntax in Netezza for the COUNT(*) in the very beginning, it works and returns a count of 60, which matches the first query above when running in Oracle. Without the WHERE clause in Netezza returns 125316 results, which matches the first query above when running in Oracle. When I use either syntax in Netezza for the SELECT * in the very beginning, I get error

ERROR [HY000] ERROR: Record size 70418 exceeds internal limit of 65535 bytes'


Solution

  • Had to use explicit columns in Netezza when doing a CROSS JOIN. Using SELECT * throws the error as indicated in my question EDIT. Also had to escape the '%' character by escaping nothing. Thank you a_horse_with_no_name. Cheers! "Where everybody knows your name." ;-)

    select A.CODE, B.CODE, LOWER(A.DIM), LOWER(B.DIM)
    FROM TABLE_A A
    cross join TABLE_A B
    WHERE A.PATH LIKE '\A\A\A%' ESCAPE '' AND A.X = 'Y'
    AND B.PATH LIKE '\B\B\B%' ESCAPE '' AND B.X = 'Y'