Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a recursive query to the general effect of:

WITH RECURSIVE text1 (selfid, parentid, text) AS 
(
SELECT DISTINCT
  text.selfid,
  text.parentid,
  text.text
FROM
  text
WHERE
  text.selfid = entryPoint
UNION ALL
SELECT
  text.selfid,
  text.parentid,
  text.text
FROM
  text,
  text1
WHERE
  text1.selfid = text.parentid
) 
SELECT
  *
FROM
  text1
ORDER BY
  text1.selfid;

I'm using this in a plpgsql function where the value entryPoint is the starting point of the recursion and is passed in.

Question: In the plpgsql, should I:

  1. code the SELECT directly into the function as above?

or

  1. programatically create a VIEW in the pl/sql function, then get my result set from the newly created VIEW?

Some of the queries will get very large result sets, sometimes as many as 500K rows (up to 4GB in the total result set). I wonder if a view would have better performance than a select.

share|improve this question
up vote 0 down vote accepted

There will be no difference in performance between a view and a straight-up query. View is basically a saved query text. If you expect to call this exact query in multiple places in your code, it may make sense to create a view. Otherwise, put a query in your pgplsql code, it will improve readability of it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.