Following the approach mentioned in [this link](https://stackoverflow.com/questions/8139618/postgresql-parameterized-order-by-limit-in-table-function/8146245), I want to pass `ORDER BY` and sorting order to a function dynamically.

`ORDER BY` is working fine but I am not able to pass sorting order (`ASC` / `DESC`).

What I have now:

```
CREATE OR REPLACE FUNCTION list(_limit integer,_offset integer,sort_by varchar(100), _order varchar(100),_category varchar(100))
  RETURNS TABLE(
     id INTEGER,
     name VARCHAR,
     clientname VARCHAR,
     totalcount BIGINT
  ) AS
$$
DECLARE
   empty text := '';
BEGIN
RETURN Query EXECUTE
'SELECT d.id,
d.name,
d.clientname,
 count(*) OVER() AS full_count FROM design_list as d 
    where ($5 = $6 Or d.category Ilike $5) 
        ORDER BY ' || quote_ident(sort_by) || ' LIMIT $1 offset $2'
USING _limit,_offset,sort_by, _order,_category, empty;
END;
$$  LANGUAGE plpgsql;

```