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

Re: PL/PGSQL - character varying as function argument

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: rod(at)iol(dot)ie
Cc: Chris Baechle <bangular(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: PL/PGSQL - character varying as function argument
Date: 2008-09-26 13:52:47
Message-ID: 48DCE92F.1050002@iol.ie (view raw or flat)
Thread:
Lists: pgsql-general
On 26/09/2008 14:41, Raymond O'Donnell wrote:
> CREATE OR REPLACE FUNCTION user_checkCredentials(character varying)
> RETURNS character varying AS
> $BODY$
> DECLARE
>      username ALIAS FOR $1;

I meant to say too that in pl/pgsql, you can use argument names directly
(unless you're using a *really* old version of PostgreSQL), making your
code easier to read:

create function user_checkCredentials(username character varying)
returns character varying as
$$
declare
  permission character varying;
begin
  select into permission permtype from users
    where uid = username;
  return permtype;
end
$$
language plpgsql;

I'd also use "character varying" for "permtype"; there's no need to use
a record as you're only only getting a single column.

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod(at)iol(dot)ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

In response to

Responses

pgsql-general by date

Next:From: Raymond O'DonnellDate: 2008-09-26 13:57:58
Subject: Re: PL/PGSQL - character varying as function argument
Previous:From: Tom LaneDate: 2008-09-26 13:47:40
Subject: Re: PL/PGSQL - character varying as function argument

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