function error - Mailing list pgsql-novice

From Jean-Yves F. Barbier
Subject function error
Date
Msg-id 20111106001952.36e955ee@anubis.defcon1
Whole thread Raw
Responses Re: function error
List pgsql-novice
Hi list,

I've made a small function but it is refused:

[blurb snipped]
DROP FUNCTION IF EXISTS get_user_oid(TEXT);
CREATE FUNCTION get_user_oid(TEXT)  -- 1- Owner's name
RETURNS OID AS $$
    SELECT usesysid AS useroid FROM pg_user WHERE usename = $1;
END;
$$ LANGUAGE sql;
REVOKE ALL ON FUNCTION get_user_oid(TEXT) FROM public;

Here's the result:

This one I understand:
=# \i ../DB_PROCS/001_GET_USER_OID_2.sql
psql:../DB_PROCS/001_GET_USER_OID_2.sql:17: NOTICE:  function get_user_oid(text) does not exist, skipping
DROP FUNCTION

This one not:
psql:../DB_PROCS/001_GET_USER_OID_2.sql:30: ERROR:  return type mismatch in function declared to return oid
DÉTAIL : Function's final statement must be SELECT or INSERT/UPDATE/DELETE RETURNING.
CONTEXTE : SQL function "get_user_oid"
psql:../DB_PROCS/001_GET_USER_OID_2.sql:34: ERROR:  function get_user_oid(text) does not exist

I succeeded with a former one, but it is plpgsl and needs a more complicated
call: SELECT * FROM get_user_oid('myusr') AS z(ooid oid); I'd prefer to
have a simpler call if possible, such as: SELECT user_oid('myusr');

JY
--
Why do seagulls live near the sea?  'Cause if they lived near the bay,
they'd be called baygulls.

pgsql-novice by date:

Previous
From: "Jean-Yves F. Barbier"
Date:
Subject: Global variables
Next
From: Tom Lane
Date:
Subject: Re: function error