Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 7C1FA9F9B35 for ; Tue, 4 Sep 2007 04:34:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 88278-03 for ; Tue, 4 Sep 2007 04:33:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from andromeda1.neonex.com.br (dns3.neonex.com.br [201.28.22.10]) by postgresql.org (Postfix) with ESMTP id 49C0D9F999D for ; Tue, 4 Sep 2007 04:33:57 -0300 (ADT) Received: from [200.206.25.4] (helo=[127.0.0.1]) by andromeda1.neonex.com.br with esmtpa (Exim 4.63) (envelope-from ) id 1ISSv3-0003Iw-G1 for pgsql-sql@postgresql.org; Tue, 04 Sep 2007 04:33:54 -0300 Message-ID: <46DD0A5E.9010400@planit.com.br> Date: Tue, 04 Sep 2007 04:33:50 -0300 From: "Luiz K. Matsumura" Organization: Plan IT Tecnologia =?ISO-8859-1?Q?Inform=E1tica_Ltda=2E?= User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: pgsql-sql@postgresql.org References: <144384.86744.qm@web31802.mail.mud.yahoo.com> <46DCFD6D.20803@planit.com.br> In-Reply-To: <46DCFD6D.20803@planit.com.br> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Antivirus: avast! (VPS 000772-1, 09/03/2007), Outbound message X-Antivirus-Status: Clean X-SA-Exim-Connect-IP: 200.206.25.4 X-SA-Exim-Rcpt-To: pgsql-sql@postgresql.org Subject: Re: Cast on character columns in views X-SA-Exim-Version: 4.2.1 (built Tue, 09 Jan 2007 17:23:22 +0000) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/23 X-Sequence-Number: 29236 Luiz K. Matsumura wrote: > > Richard Broersma Jr wrote: >> --- "Luiz K. Matsumura" wrote: >> >>> CREATE VIEW view1( id, col1, type1, type2) AS >>> SELECT table1.id, >>> table1.col1, >>> CAST( table2.type1 AS CHARACTER( 3 )), >>> NULL >>> FROM table1 >>> JOIN table2 ON table2.fk_table1 = table1.id >>> UNION ALL >>> SELECT table1.id, >>> table1.col1, >>> CAST( NULL AS CHARACTER( 3 )), >>> table3.type2 >>> FROM table1 >>> JOIN table3 ON table3.fk_table1 = table1.id; >>> >> >> Would the above changes work? >> >> Regards, >> Richard Broersma Jr. >> >> >> > Hi Richard, > Your changes works ! But now I know what mistake I did: > > The error is occurring because I'm doing a CREATE OR REPLACE VIEW > command. > The command with null:character(3) works too. > The error is because I create a view then try to change the definition > with the CREATE OR REPLACE VIEW command > When I drop the view first , and then create again the view (in a > separated transaction), now the command works! (this is a bug?) > I'm using a postgres 8.2.4 on Linux. > > Thanks a lot! > Ugh, I'm totally crazy with this views I'm using pgadmin with postgres, when I clink on "view the data of selected object" button all works fine. But when I open a query tool window and do: SELECT * FROM view1; Now, again type1 column returns as bpchar. But if I do: SELECT type1 FROM view1; Now, type1 column returns as character(3) If I do select id, col1, type1,type2 from view1; Again type1 returns as bpchar. But if I do select id, col1,type2, type1 from view1; Now type1 return as character(3). -- Luiz K. Matsumura Plan IT Tecnologia Informática Ltda.