I've gotten part-way toward implementing a CASE construct in Postgres:

  select
    case when i = 1 then 10
         when i = 2 then 20
    end
  from t;

(the other parts of the case clause are supported also). But I'm running
into problems in the executor, in that although the query tree seems to
be well-formed, there is not a corresponding plan or plan tree (not sure
of the terminology). Any suggestions on where to start, or interest in
working on it? (hint, hint)

btw, I'm hoping to have a superset of the SQL92 definition; the standard
allows only constants in the "then" clauses afaik, but I'm shooting for
allowing full expressions...

                   - Tom

Thu, 12 Nov 1998 05:48:38 +0000
"Thomas G. Lockhart" <lockhart@alumni.caltech.edu>
CASE construct
> I've gotten part-way toward implementing a CASE construct...
> ... (but) there is not a corresponding plan or plan tree (not sure
> of the terminology). Any suggestions on where to start, or interest in
> working on it? (hint, hint)

Ah, I've found Bruce's writeup on the query processing dataflow in
tools/backend/index.html.

Looks like a good place to start.

                     - Tom

Thu, 12 Nov 1998 23:32:41 +0000
"Thomas G. Lockhart" <lockhart@alumni.caltech.edu>
Re: [HACKERS] CASE construct
> > I've gotten part-way toward implementing a CASE construct...
> > ... (but) there is not a corresponding plan or plan tree (not sure
> > of the terminology). Any suggestions on where to start, or interest in
> > working on it? (hint, hint)
> 
> Ah, I've found Bruce's writeup on the query processing dataflow in
> tools/backend/index.html.
> 
> Looks like a good place to start.

I was meaning to reply to your first post, but was sick.  The way I
usually do it is to look at some feature that already uses it, and copy
that.

For the executor, they are usually spread out in many files.

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Fri, 13 Nov 1998 01:30:19 -0500 (EST)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] CASE construct
> > > I've gotten part-way toward implementing a CASE construct...
> I was meaning to reply to your first post, but was sick.  The way I
> usually do it is to look at some feature that already uses it, and 
> copy that.
> For the executor, they are usually spread out in many files.

Hope you're feeling better. How scary was the "Bruce-cam" the last few
days? :)

I've concluded that I need to make some fixups in the optimizer to get a
plan which knows about column references inside the CASE clause. In the
meantime, I've got a rudimentary capability with constants:

postgres=> select case
postgres->  when 1 > 2 then 10
postgres->  when 2 > 1 then 20
postgres->  else 30
postgres-> end;
NOTICE:  CASE/WHEN not yet implemented
?column?
--------
      20
(1 row)

I'm working on matching up types between THEN/ELSE clauses at the parser
stage, but will soon need to get back to trying to figure out the
planner. If I stall out for too long I may just commit the changes to
give someone else a chance to help out (existing features are not
damaged, so it shouldn't hurt).

                        - Tom

Fri, 13 Nov 1998 06:52:50 +0000
"Thomas G. Lockhart" <lockhart@alumni.caltech.edu>
Re: [HACKERS] CASE construct
> > > > I've gotten part-way toward implementing a CASE construct...
> > I was meaning to reply to your first post, but was sick.  The way I
> > usually do it is to look at some feature that already uses it, and 
> > copy that.
> > For the executor, they are usually spread out in many files.
> 
> Hope you're feeling better. How scary was the "Bruce-cam" the last few
> days? :)

Scary.  I avoided it.  It pops up a window when it is active, so no one
saw the scary-ness.

> I've concluded that I need to make some fixups in the optimizer to get a
> plan which knows about column references inside the CASE clause. In the
> meantime, I've got a rudimentary capability with constants:
> 
> postgres=> select case
> postgres->  when 1 > 2 then 10
> postgres->  when 2 > 1 then 20
> postgres->  else 30
> postgres-> end;
> NOTICE:  CASE/WHEN not yet implemented
> ?column?
> --------
>       20
> (1 row)

That is interesting.

> 
> I'm working on matching up types between THEN/ELSE clauses at the parser
> stage, but will soon need to get back to trying to figure out the
> planner. If I stall out for too long I may just commit the changes to
> give someone else a chance to help out (existing features are not
> damaged, so it shouldn't hurt).

Sure.  No problem.  Advantage of two trees.  (See Marc, I am learning.)

-- 
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Fri, 13 Nov 1998 05:50:34 -0500 (EST)
Bruce Momjian <maillist@candle.pha.pa.us>
Re: [HACKERS] CASE construct