How to test/read a stored procedure that returns a boolean?

Поиск
Список
Период
Сортировка
От Kevin Jenkins
Тема How to test/read a stored procedure that returns a boolean?
Дата
Msg-id 478E901D.7060701@rakkar.org
обсуждение исходный текст
Ответы Re: How to test/read a stored procedure that returns a boolean?  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
I wrote this function but I'm not sure how to test it in PG Admin III 
Query.

CREATE LANGUAGE 'plpgsql' HANDLER plpgsql_call_handler                           LANCOMPILER 'PL/pgSQL';

CREATE TABLE handles (
handleID_pk serial PRIMARY KEY UNIQUE NOT NULL,
userID_fk integer UNIQUE NOT NULL,
handle text UNIQUE NOT NULL);

CREATE TABLE disallowedHandles (
handle text UNIQUE NOT NULL);

create or replace function IsUsedHandle(h text) returns boolean as $$
declare
begin
select COUNT(*) as num_matches from handles where handles.handle = h;
return num_matches > 0;
end;
$$ LANGUAGE plpgsql;

INSERT INTO handles (handle, userid_fk) VALUES ('blah', 0);

select * from IsUsedHandle('k');

Instead of true or false, it says

ERROR: query has no destination for result data
SQL state: 42601
Hint: If you want to discard the results of a SELECT, use PERFORM instead.
Context: PL/pgSQL function "isusedhandle" line 3 at SQL statement

If I wanted to call this query and get the boolean result in C++, 
using PQgetvalue, how would I get this?

Thanks!


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Bryan Emrys"
Дата:
Сообщение: Re: SQL dealing with subquery
Следующее
От: Tom Lane
Дата:
Сообщение: Re: How to test/read a stored procedure that returns a boolean?