0

I am trying to get list of column names of a table in postgreSQL via query. I have searched online for some solutions, but none give expected results. Here is what I have tried.

select column_name
from information_schema.columns 
where table_name = 'Accounts';

it gives me:

Column_name
----------------
character varying 

What I am looking for is

Columns
-------
AccountName
AccountId
Address
ContactPerson
6
  • 2
    Your code should work. Commented Aug 6, 2019 at 12:12
  • @GordonLinoff its not working, do I need to specify DB name somewhere in this query as well ? Commented Aug 6, 2019 at 12:13
  • can you verify with following as well stackoverflow.com/questions/20194806/… Commented Aug 6, 2019 at 12:14
  • @Addy . . . You can specify the schema. But your code is returning the type column. column_name should be the column name. It is unlikely that there is a column named "character varying" anywhere the in the database, but it is, of course, possible. Commented Aug 6, 2019 at 12:14
  • Got it adding "table_catalog" worked for me... Commented Aug 6, 2019 at 12:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.