Skip site navigation (1) Skip section navigation (2)

Re: Function proposal to find the type of a datum

From: Richard Huxton <dev(at)archonet(dot)com>
To: Kate F <kate(at)cats(dot)meow(dot)at>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Function proposal to find the type of a datum
Date: 2007-02-02 10:09:24
Message-ID: 45C30DD4.1050105@archonet.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Kate F wrote:
> I see my misunderstanding: '2' IS OF (INTEGER) yields false: fine.
> However I was expecting that pg_type_of('2') would return 'INTEGER': it
> wouldn't, of course. So, I understand you here: there would be no
> difference between this and IS OF in the way I had imagined.

It's not even possible to have a function that determines the type of a 
value given that we have overlapping types. How do you know that "2" 
isn't an int8 rather than int4, or numeric, or just text. What about 
'now'? That's a valid timestamp as well as text.

Now, if we had an can_be_cast_to(TEXT-VAL,TYPE) that would at least let 
you check against a pre-determined list of types. The only way I know of 
at present is to trap an exception if it fails.

I think you're going to have to store your arguments with their types.

-- 
   Richard Huxton
   Archonet Ltd

In response to

Responses

pgsql-hackers by date

Next:From: Csaba NagyDate: 2007-02-02 10:14:15
Subject: Re: Referential Integrity and SHARE locks
Previous:From: Simon RiggsDate: 2007-02-02 09:51:36
Subject: Referential Integrity and SHARE locks

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group