I'm new to Postgres. I tried to run the following in pgAdmin/DBeaver but getting "ERROR: query has no destination for result data" error
do $$
declare customerid integer := 151;
begin
SELECT * FROM get_orders(customerid);
end $$
My guts tell me that it is something simple. What do I need to change so it will display the results in DBeaver or pgAdmin?
I don't want something like this:
SELECT * FROM get_orders(151);
I do want to use something like a variable to separate from the actual select statement. Thanks.
script segments to prepare the table/function
------------------
CREATE TABLE orders
(
id integer,
customerid INTEGER,
description varchar(100)
)
------------------
INSERT INTO Orders VALUES
(1,101, 'Test Order 1'),
(2,151, 'Random Order')
------------------
CREATE OR REPLACE FUNCTION get_orders (p_customerid int)
RETURNS TABLE (
id integer,
customerid INTEGER,
description varchar(100)
)
AS $$
BEGIN
RETURN QUERY SELECT
*
FROM
orders ord
WHERE
ord.customerid = p_customerid;
END; $$
LANGUAGE 'plpgsql';