1

How can I make this query works?

I've the function top_movies_ceiling(3)

CREATE OR REPLACE FUNCTION top_movies_ceiling(n_top integer)  -- n_top dos mais vendidos
RETURNS SETOF inventory AS $$
BEGIN
RETURN QUERY
SELECT *
FROM inventory
ORDER BY sales DESC
LIMIT n_top;
END;
$$LANGUAGE plpgsql; 

that returns:

prod_id|quan_in_stock|sales

Now, when I run the query:

SELECT products.price 
FROM products
WHERE products.prod_id = prod_id.top_movies_ceiling(3);

I get the error: schema "prod_id" does not exist

I hope that you can help me! Thanks!

2
  • why you use prod_id.top_movies_ceilin?.. Commented Oct 13, 2017 at 9:04
  • Because I've opened a Cursor and i've been fetch it into a numeric variable from the same type that "prod_id", for the purpose to save it. Commented Oct 13, 2017 at 9:07

2 Answers 2

2

a wild guess - is it what you try to do?

SELECT products.price 
FROM products
JOIN (select * from top_movies_ceiling(3)) top_m on top_m.prod_id = products.prod_id
;
Sign up to request clarification or add additional context in comments.

Comments

1

The error is in:

prod_id.top_movies_ceiling(3)

that mean: function top_movies_ceiling(int) from schema prod_id.

Please enter the CREATE FUNCTION of top_movies_ceiling() for better understand what you want.

Comments

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.