postgresql field size information

From: Date: Thu, 27 May 2004 15:36:41 +0000
Subject: postgresql field size information
Groups: php.db 
Request: Send a blank email to php-db+get-34573@lists.php.net to get a copy of this message
I need to get the size of the fields defined in a postgresql table for use in my PHP script. For instance: $fieldname = pg_field_name($stat,$i); $size = pg_field_size($stat,$i); $type = pg_field_type($stat,$i); I tried using pg_field_size but for char type fields it returns a -1 indicating the field is variable length. I need to get the defined size of the field. pg_field_prtlen does not appear to be the correct function to return this type of information. I did get most of what I needed from this query: $stat = pg_query($dbh,"select attname,atttypmod from pg_class c join pg_attribute a on c.oid = a.attrelid where c.relname = '$tablename' and a.attnum >= 0"); But the atttypmod field appears to have some overhead included (4 bytes). I can adjust for that but there must be an easier way to get the information for a field defined in a table. Suggestions on how to do this? -- Scot L. Harris <webid@cfl.rr.com>

« previous php.db (#34573) next »