Thread: 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
<div class="gmail_quote">On Sat, Mar 6, 2010 at 4:34 PM, Gianvito Pio <span dir="ltr"><<a href="mailto:pio.gianvito@gmail.com">pio.gianvito@gmail.com</a>></span>wrote:<br /><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> Hi all,<br /> is there away to check if two attribute are type compatible (for example integer and serial, integer and integer, character varyingand text, etc..)?<br /><br /> Example:<br /> IF (compatible (table1.att1, table2.att2)) THEN<br /> ...<br />ELSE<br /> ...<br /> END IF;<br /><br /> Thanks<br /><font color="#888888"><br /><br /> -- <br /> Sent via pgsql-sqlmailing list (<a href="mailto:pgsql-sql@postgresql.org" target="_blank">pgsql-sql@postgresql.org</a>)<br /> To makechanges to your subscription:<br /><a href="http://www.postgresql.org/mailpref/pgsql-sql" target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><br/></font></blockquote></div><br />Explain in more detail.<brclear="all" /><br />-- <br />Nilesh Govindarajan<br />Site & Server Administrator<br /><a href="http://www.itech7.com">www.itech7.com</a><br/><br />
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 conversionwhich 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@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Gianvito Pio Sent: Saturday, March 06, 2010 5:04 AM To: pgsql-sql@postgresql.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 -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql