Skip site navigation (1) Skip section navigation (2)

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

From: Kevin Jenkins <gameprogrammer(at)rakkar(dot)org>
To:
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to test/read a stored procedure that returns a boolean?
Date: 2008-01-16 23:50:41
Message-ID: 478E9851.9020905@rakkar.org (view raw or flat)
Thread:
Lists: pgsql-sql
Thanks Tom!

Also, how do I check if a language is already created so I don't load 
it twice?

"ERROR: language "plpgsql" already exists
SQL state: 42710"

Here is the code fixed.

/*
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
	num_matches integer;
begin
	num_matches := COUNT(*) 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('blah');

In response to

pgsql-sql by date

Next:From: Gerardo HerzigDate: 2008-01-18 14:17:46
Subject: transaction and triggers
Previous:From: Tom LaneDate: 2008-01-16 23:28:40
Subject: Re: How to test/read a stored procedure that returns a boolean?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group