Roundtrip SQL bug/ unanticipated behaviour

From: Angus Carr <angus(dot)carr(at)gmail(dot)com>
To: pgadmin-support(at)postgresql(dot)org
Subject: Roundtrip SQL bug/ unanticipated behaviour
Date: 2009-07-16 20:08:44
Message-ID: be64ca450907161308w2388440u8500223853abc964@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

I created a median function based on some code from the web. That was a few
months ago. Today, I wanted the 25th and seventy-fifth percentiles. I wanted
to modify the code used in the median function to do the percentiles.

The following code works. However, if I run it, then find the created object
(code.percentile25) in pgadmin, get the create script, and then execute the
create script, it fails, being unable to find the array function.

It seems that the create script returned from pgadmin adds in quotation
marks around the function name in the FINALFUNC line, which causes the code
to no longer work.

I am sending this to pgadmin, because I haven't got a clue whether the code
returned in the create script is parsed by pgadmin or postgresql. I'm sure
you folks know better than I.

Cheers,
Angus Carr.

================== code below. ================
CREATE OR REPLACE function code.array_percentile25(numeric[])
RETURNS numeric AS
$BODY$
SELECT CASE WHEN array_upper($1,1) = 0 THEN null ELSE
asorted[ceiling(array_upper(asorted,1)*0.25)] END
FROM (SELECT ARRAY(SELECT ($1)[n] FROM
generate_series(1,array_upper($1,1)) AS n
WHERE ($1)[n] IS NOT NULL
ORDER BY ($1)[n]
) AS asorted
) AS foo ;
$BODY$
LANGUAGE 'sql' IMMUTABLE
COST 100;
--ALTER FUNCTION code.array_percentile75(numeric[]) OWNER TO postgres;
ALTER FUNCTION code.array_percentile25(numeric[]) OWNER TO apc;

CREATE AGGREGATE code.percentile25(numeric) (
SFUNC=array_append,
STYPE=numeric[],
FINALFUNC=code.array_percentile25
);

Browse pgadmin-support by date

  From Date Subject
Next Message Rainer Bauer 2009-07-17 09:56:43 pgAdmin3 Version 1.10.0 : Crash when configuring an pgAgent job
Previous Message Quan Zongliang 2009-07-15 23:01:12 Re: I need help, about c++ pointer