Write a recursive query in SQL for postgres.
- User
Write a recursive query in SQL for postgres.
Assistant
Here is a sample SQL query for a Postgres database for a recursive query:
codeWITH RECURSIVE cte AS ( SELECT ROW_NUMBER() OVER (ORDER BY id) AS row, id, name FROM my_table WHERE id = [1] FOR XML PATH(''), ROOT('root') ) SELECT * FROM cte WHERE row = 1;This query defines a recursive CTE that retrieves the first record with a given ID. The CTE is defined with an XML path that specifies the root element of the data. The outer query then selects all records where the row equals 1.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.