pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stephane Schildknecht <sschildknecht@aurora-linux.com>
To: pgsql-sql@postgresql.org
Subject: Boolean to int
Date: 04 Jul 2002 19:26:35 +0200
Message-ID: <1025803595.20819.239.camel@fukse> (raw)

Hi, 

        I'd like to get 1 or 0 from a select on a boolean field. 

How could I do ?

I tried the following rule, which I can't insert :

CREATE FUNCTION bool_to_int( boolean ) RETURNS integer AS '
        DECLARE
                my_bool ALIAS FOR $1 ;
        BEGIN
                -- Retourne 1 si true, 0 si false
                IF my_bool IS FALSE THEN 
                        RETURN 0 ;
                ELSIF my_bool IS TRUE THEN
                                RETURN 1 ;
                ELSE RETURN -1 ;
                END IF ;
        END ;
' LANGUAGE 'plpgsql';

CREATE RULE boolean_return AS ON SELECT TO DOCUMENT DO INSTEAD
        SELECT 
        document_id,
        workflow_id,
        type_document_id,
        image_id,
        theme_id,
        document_version,
        document_surtitre,
        document_titre,
        document_chapeau,
        document_synthese,
        document_corps,
        document_pdf,
        document_date_creation,
        document_mot_clef,
        (bool_to_int(document_online)) as document_online,
        bool_to_int(document_valid) as document_valid FROM document;


psql:cnambo_proc_stock.sql:69: ERROR:  select rule's target entry 15
 has different type from attribute document_online

Who could help me ?

S@S

-- 
 _Stéphane SCHILDKNECHT___________________________________
| AurorA-SAS 69-71, Av. Pierre Grenier 92100 BOULOGNE     |
| Tel : 01.58.17.03.20 Fax : 01.58.17.03.21               | 
| mailto:sschildknecht@aurora-linux.com - ICQ : 142504394 |
| "Free Markets have taught that innovation is best when  | 
|  ideas flow freely." Adam Smith                         |
|_________________________________________________________|






view thread (5+ messages)  latest in thread

Message-ID: <1025803595.20819.239.camel@fukse>
Permalink:  ../1025803595.20819.239.camel@fukse/
Also on:    postgresql.org/message-id/1025803595.20819.239.camel@fukse

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: sschildknecht@aurora-linux.com
  Subject: Re: Boolean to int
  In-Reply-To: <1025803595.20819.239.camel@fukse>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox