December 19th, 2001, 07:46 AM
Does anyone know where in the system tables I can find the length of a particular column?
I've had a look in the pg_attribute table, but it doesn't appear to show me the max length of my VarChar fields - the length appears as -1 (variable).
Also, in which table is an attribute linked to a table? My hunch is that a lot of system table data is hidden from view but if anyone knows how I might get as the things I've mentioned, I'd be very grateful.
Thanks in advance, NICK
December 24th, 2001, 05:25 AM
For variable length fields, you need to check the atttypmod field. Postgres will add four more bytes (presumably to hold the actual size of the data?). For example, if a column is varchar(25), its value in atttypmod will be 29. By the way, in case your interested, the PHP function pg_fieldsize will only ever return '-1' for varchar fields, which I think is pretty weak. Fortunately it's a simple fix, just patch <php_4.1_source>/ext/pgsql/pgsql.c with this:
Sorry, just noticed the other part of your post: check out the online manual at http://www.postgresql.org/idocs/index.php?catalogs.html (I think there's even a mirror in Britain.)
> if ( return_value->value.lval == -1 )
> return_value->value.lval = PQfmod( pgsql_result, Z_LVAL_PP(field) );
Last edited by billyo; December 24th, 2001 at 05:30 AM.