The psql command line has several shortcuts, such as \d , but is not part of SQL. You need to request information_schema :
SELECT column_name FROM information_schema.columns WHERE table_name = 'my_table';
EDIT: This is really important information that the psql -E command line will display SQL queries used to implement \d and other backslash commands (whenever you use one of them on the psql command line) like @ piro wrote in a comment. Thus, you get what you want very easily.
Thanks @piro!
source share