Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
we written in sql select * from <tablename>

what a synax in postgress

What I have tried:

postgress query of select statement to fetch whole table
Posted
Updated 1-Apr-18 23:32pm
Comments
RickZeeland 26-Mar-18 11:57am    
Please clarify if you are using a programming language or using PL/pgSql or something else ...
Member 13140552 2-Apr-18 4:31am    
pgSQL

 
Share this answer
 
I seldom use pgSQL, and mostly use it from .NET with the NpgSQL driver, but here are some examples. Sadly I got no output displayed in the pgAdmin window, but saving the results to a file worked.
Simple example from PostgreSQL wiki[^]
--DROP FUNCTION getemployees();
create function GetEmployees() returns setof employee as 'select * from employee;' language 'sql';
select * from GetEmployees();

Here is a more elaborate example from PL/pgSQL Declaration - w3resource[^]
CREATE FUNCTION get_employee(text) RETURNS text AS '
  DECLARE
     frst_name ALIAS FOR $1;
     lst_name employees.last_name%TYPE;
  BEGIN
     SELECT INTO lst_name last_name FROM employees 
	 WHERE first_name = frst_name;
     return frst_name || '' '' || lst_name;
  END;
' LANGUAGE 'plpgsql';
And then call it like this:
SELECT get_employee('John');

You can also call your functions in PgAdmin by right-clicking on them in the tree on the left and then use 'Scripts - Select Script', this way the output will be displayed in the output window.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900