简体   繁体   中英

How can I re-use a function name as an out-parameter in PostgreSQL 8?

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 RECORD s 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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM