-1

How do I convert this connect by oracle sql query to Postgres recursive with?

 SELECT DISTINCT connect_by_root(po1.product_offer_name) AS Offer
        po.product_offer_id product_offer_id
      FROM product_offer_offer poo,
        product_offer po,
        product_offer po1
      WHERE connect_by_isleaf = 1
      AND po.product_offer_id = poo.child_product_offer_id
      AND po1.product_offer_id = poo.product_offer_id
        START WITH poo.product_offer_id IN
        (SELECT product_offer_id
        FROM product_offer
        WHERE sysdate BETWEEN available_start_date AND available_end_date
        AND product_id        IS NOT NULL
        AND     (:TopLevelOffer = 0 OR product_offer_id = :TopLevelOffer)
        )
        CONNECT BY prior poo.child_product_offer_id = poo.product_offer_id 

What should be the recursive query for this oracle code trying to get products and their child products

2
  • 1
    postgresql.org/docs/current/… Commented Oct 13, 2022 at 12:01
  • Welcome to the SO community. The community will help with your issues, but there are certain expectations on you. Please take a few minuets to take the Tour and review How to Ask. Then update your question to include sample data, table definition (ddl scripts), the expected results of that data , all as text - no images. Further clearly describe what you are attempting, not how but what, and where you are having issues. What does the current query produce? Commented Oct 13, 2022 at 22:46

1 Answer 1

-2

CONNECT BY is a proprietary functionnality for recursive queries. The SQL ISO standard is based on CTE for RECURSIVE queries.

Just convert the query to the ISO standard SQL and everything will be done.

https://www.sqlservercentral.com/articles/recursive-queries-in-sql1999-and-sql-server-2005

Sign up to request clarification or add additional context in comments.

3 Comments

This is not a valid answer as OP's question could be rephrased as how to convert Oracle proprietary hierarchy query to standard sql? Furthermore references to MS SQL Server do not necessary apply to Postgres.
This paper is about ISO Standard SQL about CTE and recursive queries, and applies to SQL Server and PostGreSQL too, that conforms the standard...
What is the alternative for Connect by isleaf in postgres, everything else is fine but I can't get what condition to use in place of connect by isleaf=1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.