Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

Re: [GENERAL] mssql migration and boolean to integer problems

From: Adrian Klaver <aklaver(at)comcast.net>
Date: Fri Dec 14 2007 - 21:46:17 EST


On Wednesday 12 December 2007 8:09 pm, robert wrote:
> Hi all, I've spent the last few days hacking a mssql INSERT script to
> work with 8.1.9 - I could build the latest postgres source if need be.
> My latest problem is:
>
> ERROR: column "includeScenario" is of type boolean but expression is
> of type integer
> HINT: You will need to rewrite or cast the expression.
>
> So mssql uses tiny int for booleans, and I have about 50 of
> those ;-) . I googled alot on this, and tried 4 or 5 different ideas
> with Functions and alter tables - but I can't find anything that's
> working with 8.1.9, can someone please help me?
>

In 8.2 there is a built in int --> bool cast. I had a similiar problem with 8.0 and I created my own int::bool cast using the following:

CREATE CAST (int4 AS bool)
  WITH FUNCTION bool(int4)
  AS ASSIGNMENT; CREATE OR REPLACE FUNCTION bool(int4)
  RETURNS bool AS
$Body$
Declare

        output char(1);
Begin

        Select into output $1;
Return output;
End;
$Body$
  LANGUAGE 'plpgsql' VOLATILE;

This way I did not have to include the casting in SQL statements. Be aware that if you upgrade to 8.2 the restore process will weed out the above because of the builtin cast.

-- 
Adrian Klaver
aklaver@comcast.net

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
Received on Fri Dec 14 21:46:22 2007

This archive was generated by hypermail 2.1.8 : Mon Jun 16 2008 - 22:25:30 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library