Export DESCRIBE TABLE from Postgres to txt

0

Is it possible to generate a .txt file with the DESCRIBE TABLE from a table in Postgres by PHP? I need to download a .txt file with the description of the fields (name, type, character size) of the table where the query is being made.

    
asked by anonymous 02.05.2017 / 15:09

1 answer

0

You can first make the select in INFORMATION_SCHEMA, and then use Copy. I do not know if the text formatting suits you, but it's a starting point.

Example:

COPY (select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS where table_name = 'nome_da_tabela') TO 'd:\nome_da_tabela.txt'
    
04.05.2017 / 13:53