PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 19th, 2001, 07:46 AM
cresswelln cresswelln is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Location: London, England
Posts: 14 cresswelln User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Column Length

Hi,

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

Reply With Quote
  #2  
Old December 24th, 2001, 05:25 AM
billyo billyo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 114 billyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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:
Code:
1018a1019,1021
>                       if ( return_value->value.lval == -1 )
>                               return_value->value.lval = PQfmod( pgsql_result, Z_LVAL_PP(field) );
>


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.)

Last edited by billyo : December 24th, 2001 at 05:30 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Column Length


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT