1

I'm fetching data from a PostgreSQL database. All is working fine, however i want to select the size of the data_type as well however i cant get that to work. Please help Here's my query:

 $result2 = pg_query($dbconn, "SELECT table_name as tabela, column_name as campo, data_type as tipo from information_schema.columns where table_schema = 'public'");

1 Answer 1

1

your sql works fine.

I'd say you user does not have permission (Read) to the table(s) its asking to view ?

You could try this

GRANT SELECT ON ALL TABLES IN SCHEMA PUBLIC TO youruser;

For the size of the column you could you the System Administration Function

pg_column_size(data_type)

" pg_column_size(any) returns an int Which is the Number of bytes used to store a particular value (possibly compressed) "

SELECT table_name as tabela, column_name as campo, 
data_type as tipo,pg_column_size(data_type) as tipo1 from
information_schema.columns where table_schema = 'public'

Results

Postgresql Results set using pg_column_size

Ref Postgresql 9.5 section 9.26. System Administration Functions

All the best

4
  • i know my sql works fine, but i want something like column_length as length to get the size of the field... if thats possible :(
    – Boltz0r
    Commented May 12, 2016 at 10:52
  • Hi @Boltz0r I hope this is what you're looking for? All the best
    – user1123335
    Commented May 12, 2016 at 11:19
  • I'm not sure if he gives me the size of the type itself or the size of "integer" f ex.... but that's something ;) I'll count that as solved :D Thanks!
    – Boltz0r
    Commented May 12, 2016 at 11:23
  • Hi @Boltz0r pg_column_size(any) returns an int Which is the Number of bytes used to store a particular value (possibly compressed)
    – user1123335
    Commented May 12, 2016 at 11:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.