Export DESCRIBE TABLE from Postgres to txt

Asked

Viewed 130 times

0

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

1 answer

0

First you can select in INFORMATION_SCHEMA, and then use Copy. I don’t know if the formatting of the text 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'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.