Thread: system catalog and varchar datatype
hi, I need to find out the length of a varchar attribute .. for example,if a I have an atribute "description varchar(256)" I would expect to see this "256" in the pg_attribute table. there's is an "attlen" In the pg_attribute but this doesn't give any information thanks in advance. _________________________________________________________________ MSN Amor: busca tu ½ naranja http://latam.msn.com/amor/
On Mon, 2004-07-19 at 21:58, sandra ruiz wrote: > hi, I need to find out the length of a varchar attribute .. > > for example,if a I have an atribute "description varchar(256)" I would > expect to see this "256" in the pg_attribute table. > > there's is an "attlen" In the pg_attribute but this doesn't give any > information SELECT pg_catalog.format_type(a.atttypid, a.atttypmod) FROM pg_attribute AS a; would return "character varying(10)" or similar. -- Oliver Elphick olly@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA ======================================== "Blessed is the man that trusteth in the LORD, and whose hope the LORD is." Jeremiah 17:7
On Mon, 19 Jul 2004, sandra ruiz wrote: > hi, I need to find out the length of a varchar attribute .. > > for example,if a I have an atribute "description varchar(256)" I would > expect to see this "256" in the pg_attribute table. > > there's is an "attlen" In the pg_attribute but this doesn't give any > information Atttypmod gives this information, but the value is datatype specific. For varchar (and char) at least, the atttypmod is 4 greater than the maximum length, so atttypmod for the above would be 260.
For my purposes, I was happier to get the output of format_type() and parse it. This meant that I didn't have to carry around some magic constant that wasn't part of the documented interface... Tony On Jul 19, 2004, at 2:31 PM, Stephan Szabo wrote: > On Mon, 19 Jul 2004, sandra ruiz wrote: > >> hi, I need to find out the length of a varchar attribute .. >> >> for example,if a I have an atribute "description varchar(256)" I >> would >> expect to see this "256" in the pg_attribute table. >> >> there's is an "attlen" In the pg_attribute but this doesn't give any >> information > > Atttypmod gives this information, but the value is datatype specific. > > For varchar (and char) at least, the atttypmod is 4 greater than the > maximum length, so atttypmod for the above would be 260. > > ---------------------------(end of > broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >