I want to fetch all the fields data but don't want to specify the fields name and don't want to create a view. I have tried
WITH orderschema as
(SELECT array_to_string(ARRAY(SELECT c.column_name
FROM information_schema.columns As c
WHERE table_name = 'orders'
AND c.column_name NOT IN('Quantity')
), ','))
SELECT * from orderschema
but this is returning the schema fields name as a single string and i can't use this single string to get all the fields from the orders table. is there any way to exclude the field directly in psql?
Generally speaking no such way exists.
But - if you plan on converting data to JSON in Pg (which you shouldn't for performance reasons, but you might if you really, really want to), you could just delete the column from json.
The best way, though, is to write query that lists only the columns you need.