Casting - Mailing list pgsql-general

From Nigel J. Andrews
Subject Casting
Date
Msg-id Pine.LNX.4.21.0304081002330.24319-100000@ponder.fairway2k.co.uk
Whole thread Raw
Responses Re: Casting  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general

I'm obviously missing something here but I don't know what. This is on 7.3.2.
When I use my cast I get:

mydb=> select cast('truE'::text as boolean);
WARNING:  Error occurred while executing PL/pgSQL function text_to_bool
WARNING:  line 4 at select into variables
ERROR:  CopyQuerySnapshot: no snapshot has been set

Any clues as to why that is?

The code is simplistic to say the least:


-- text_to_bool ()
--
-- Cast from text type to boolean.
--
CREATE OR REPLACE FUNCTION text_to_bool ( text )
    RETURNS boolean
    AS '
    DECLARE
        rv    boolean;
    BEGIN
        SELECT INTO rv
            CASE
                WHEN lower($1) = ''true''
                    OR lower($1) = ''t''
                    OR lower($1) = ''1''
                THEN
                    true
                WHEN lower($1) = ''false''
                    OR lower($1) = ''f''
                    OR lower($1) = ''0''
                THEN
                    false
                ELSE
                    NULL
                END;
        RETURN rv;
    END;
    '
    LANGUAGE 'plpgsql'
    STRICT
    IMMUTABLE;

CREATE CAST (text AS boolean) WITH FUNCTION text_to_bool ( text );


Thanks,

--
Nigel J. Andrews


pgsql-general by date:

Previous
From: Jean-Christian Imbeault
Date:
Subject: Re: Instalation problem
Next
From: Laurent Perez
Date:
Subject: CVS doesn't compile initdb and other binaries