views:

91

answers:

1

I have a function that has a very useful name: has_useful_state(param).

I have a second function that will be returning a SETOF RECORDs of these results:

CREATE OR REPLACE FUNCTION set_of_useful_things(param TEXT, OUT has_useful_state) RETURNS SETOF RECORD AS $_$
BEGIN
    SELECT some_key, COUNT(has_useful_state(some_key)) FROM ....

At any rate, here's where it goes off the rails. The function, where has_useful_state is by far the best name for both the return column name and for the function that provides it, fails to compile with an error like this:

SELECT some_key, COUNT( $1 (some_key)) FROM ....

Obviously the function name is being treated as an alias... so how can I avoid this and still keep my useful function and column names?

+1  A: 

You may as well insist on having two variables by the same name, but most of the time we have to put up with their nasty habit of shadowing each other.

In short, no, you can't, you'll have to change one of those (my guess is that you will sacrifice a parameter).

Michael Krelin - hacker
Really? You mean that this... 'programming language' doesn't even have the concept of context-dependent symbol tables? WTF? This is like trying to program in C macros exclusively. Garbage.I'll hope that someone else has a solution, but if not I'll be back to bump yours up.
Chris R
Well, yes, isn't `$1` hinting at macro-expansion nature of the aliases processing?
Michael Krelin - hacker
You can see for yourself how many namespaces there are ;-) http://git.postgresql.org/gitweb?p=postgresql.git;a=blob;f=src/pl/plpgsql/src/gram.y;h=af398f28ba43c2c32e13f584d1a0942b68f598e3;hb=HEAD#l377
Michael Krelin - hacker