Home > Archive > PostgreSQL Discussion > March 2006 > checking data type









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author checking data type
raj

2006-03-28, 3:27 am

is there a function that could check for a variable's data type? like
i want to check all the columns of a table and if i found a column with
an integer data type i set it to a default 1 and i'll set a constant
to a column of type text.

Chris

2006-03-29, 8:26 pm

raj wrote:
> is there a function that could check for a variable's data type? like
> i want to check all the columns of a table and if i found a column with
> an integer data type i set it to a default 1 and i'll set a constant
> to a column of type text.


You could start psql with -E:

psql -d dbname -E

run \d <tablename>

and use the queries that postgres runs to work it out..

There could be a simpler way though in the system catalogues (anyone?).


I should ask why you need this info ;)

--
Postgresql & php tutorials
http://www.designmagick.com/

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

raj

2006-03-29, 8:26 pm

Hi, Chris (great looking site, by the way)! thanks for responding. i
was just practicing on postgres and encountered this problem. i am
using pg admin for postgres and for some reason the commands you posted
does not seem to work. i was kinda looking for an built-in function
like "upper() or max()".

Chris

2006-03-31, 3:30 am

raj wrote:
> Hi, Chris (great looking site, by the way)! thanks for responding. i
> was just practicing on postgres and encountered this problem. i am
> using pg admin for postgres and for some reason the commands you posted
> does not seem to work. i was kinda looking for an built-in function
> like "upper() or max()".


http://www.postgresql.org/docs/8.1/...ion-schema.html

specifically

http://www.postgresql.org/docs/8.1/...ma-columns.html

So you end up with:

SELECT * from information_schema.columns where
table_name='your_tab
le_name' and column_name='your_co
lumn_name';

There is a lot of data there, but you should be able to find what you need.

--
Postgresql & php tutorials
http://www.designmagick.com/

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com