The one problem is that neither function nor views can return the columns with same names (in your example columns CustomerID presented in both tables). And the another one - syntax:
RETURNS TABLE ( column_name column_type [, ...] )
from the official doc, nothing about table_name.*.
Aside of the obvious solution where you specifying the complete list of columns, there is one trick with composite (row, record) types:
CREATE FUNCTION get_data (p_pattern VARCHAR,p_year INT)
RETURNS TABLE (order orders, customer customers)
AS $$
Note that you can use table/view names as types in declarations.
And in that case your query could looks like
SELECT a, b
FROM Orders a
JOIN Customers b ON a.CustomerID=b.CustomerID
After that the usage of the function would be:
select
*, -- two composite columns
(order).*, -- all columns from table orders
(customer).*, -- all columns from table customers
(order).CustomerID -- specific column from specific table
from
get_data(<parameters here>);
dbfiddle
select *selects from all tables in the query in every DBMS I have ever used. Does PostGreSQL differ here? That seems weird/unlikely to me. And yes, "I am not able to X" is not a valid problem description.selectstatement from the desired tables/columns, not just the table names. Also, presumably you really intend for the function arguments to be used in thewhereclause, as otherwise the function would not achieve anything useful.select * from tblA inner join tblB on blahand get all the columns just fine. You then need to incorporate that select into your function in a syntactically correct way, not what you've tried above.