Re: Check type compatibility

From: "Little, Douglas" <DOUGLAS(dot)LITTLE(at)orbitz(dot)com>
To: Gianvito Pio <pio(dot)gianvito(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Check type compatibility
Date: 2010-03-06 13:21:57
Message-ID: A434C531E37AD442815608A769550D8059422B97FB@EGEXCMB01.oww.root.lcl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,
I believe types are compatible if they can be cast automatically.
The pg_cast table record all possible casts between types. If it castcontext is 'a' then I belive it's an automatic conversion which is what I think you want. 'i' implicit means that cast is possible, but must be explicitly cast.

I suspect that you'll need to write a function that consults the table for the type pair.

Cheers
Doug

-----Original Message-----
From: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Gianvito Pio
Sent: Saturday, March 06, 2010 5:04 AM
To: pgsql-sql(at)postgresql(dot)org
Subject: [SQL] Check type compatibility

Hi all,
is there a way to check if two attribute are type compatible (for
example integer and serial, integer and integer, character varying and
text, etc..)?

Example:
IF (compatible (table1.att1, table2.att2)) THEN
...
ELSE
...
END IF;

Thanks

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Louis-David Mitterrand 2010-03-06 13:31:27 Re: an aggregate to return max() - 1 value?
Previous Message Nilesh Govindarajan 2010-03-06 11:22:12 Re: Check type compatibility