pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: José Soares <jose@sferacarta.com>
To: Matthew Hagerty <matthew@venux.net>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] Urgent, bool-to-int patch possible?
Date: Thu, 15 Apr 1999 15:11:51 +0200
Message-ID: <3715E597.C174227A@sferacarta.com> (raw)
References: <4.1.19990414140053.0096de40@mail.venux.net>



Matthew Hagerty ha scritto:

> Greetings,
>
> What would be the chances of getting a patch for 6.4.2 to do bool-to-int
> conversion?  I need to do a query similar to this:
>
> SELECT * FROM mytable ORDER BY
> int(col1 > 3) + int(col2 < 4) + ... other conditions;
>
> (courtesy of Tom Lane)
>
> Would it be that hard to make a patch to do the conversion?  I would try it
> myself but I have no idea where to start looking, and I need this sooner
> than I could probably figure it out.
>
> I'm not making demands or stomping my feet, I love postgres and I
> understand that it is free software, but if one of you feels really nice... :)
>
> Thanks,
> Matthew

This function converts a bool to a smallint...

create function int2(bool) returns int2 as
'begin
        IF $1 THEN
            RETURN 1;
        ELSE
            RETURN 0;
        END IF;
 end;'   language 'plpgsql';

example:
     SELECT * FROM mytable ORDER BY
    int2(col1 > 3) + int2(col2 < 4) + ... other conditions;

-----
José





view thread (3+ messages)  latest in thread

Message-ID: <3715E597.C174227A@sferacarta.com>
Permalink:  ../3715E597.C174227A@sferacarta.com/
Also on:    postgresql.org/message-id/3715E597.C174227A@sferacarta.com

 · 

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-interfaces@postgresql.org
  Cc: jose@sferacarta.com, matthew@venux.net
  Subject: Re: [INTERFACES] Urgent, bool-to-int patch possible?
  In-Reply-To: <3715E597.C174227A@sferacarta.com>

* 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