Two questions about Postgres parser

From: Konstantin Knizhnik <k(dot)knizhnik(at)postgrespro(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Two questions about Postgres parser
Date: 2017-02-27 16:07:54
Message-ID: f3c9d019-d12e-3f2b-1aea-73747e660513@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

Working on vectorized extension for Postgres (VOPS) I faced with two
things in Postgres compiler which break my expectations and force me to
abandon my original implementation plan. I wonder if it is really
principle and correct that:

1. Moving-aggregate implementation should return the same type as plain
implementation. Yes, in most cases it is hard to find arguments why them
should return different types. But it is not true for vectorized
operations...

2. Implicit user defined type casts are not applied for COALESCE operator:

create type complex as (x float8, y float8);
create function float2complex(x float8) returns complex as $$
declare complex c; begin c.x := x; x.y = 0; return c; $$ language
plpgsql strict immutable;
create cast (float8 as complex) with function float2complex(float8)
as implicit;
create table foo(c complex);
select coalesce(c, 0.0) from foo;
ERROR: COALESCE types complex and numeric cannot be matched
LINE 1: select coalesce(c, 0.0) from foo;

select coalesce(c, 0.0::float8) from foo;
ERROR: COALESCE types complex and double precision cannot be matched
LINE 1: select coalesce(c, 0.0::float8) from foo;

select coalesce(c, 0.0::float8::complex) from foo;
coalesce
----------
(0 rows)

--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Steele 2017-02-27 16:09:49 Re: Creation of "Future" commit fest, named 2017-07
Previous Message Robert Haas 2017-02-27 15:58:10 Re: bytea_output output of base64