On 2009-11-18, Thomas Løcke <thomas(dot)granvej6(at)gmail(dot)com> wrote:
> Content-Type: text/plain; charset=ISO-8859-1
> Hey all,
> The above function appears to be doing exactly what I want: Fetch the users
> data and update the visits column, if the supplied credentials match a user.
> My problem is what happens when the credentials don't match a user. In those
> cases I would like to have a boolean false returned, but instead I get an
> empty array - which of course is entirely according to the functions "RETURN
> SETOF users" statement.
> Is this little problem solvable, or will I have to learn to live with the
> empty array?
array? how are you calling it?
your function seems basically equivalent to
UPDATE users SET lastvisit = now(), visits = visits + 1
WHERE username = uname AND password = passwd
anyway you'll have to look at the number of results returned, or
re-write it to only return a single result (I'm assumuing you don't
allow multiple accounts with the same username and password)
then you can return a special value for not found (perhaps 0)
personally I'd go with the sql given above and use apropriate means to
ask how many results were returned.
pg_num_rows(), FOUND, etc...
OTOH you say array, perhaps your chosen platform already treats an
array with zero elemants like false?
In response to
pgsql-novice by date
|Next:||From: Jasen Betts||Date: 2009-11-20 09:50:48|
|Subject: Re: My second PL/pgSQL function - minor problem|
|Previous:||From: Thomas Kellerer||Date: 2009-11-19 19:14:27|
|Subject: Re: Noob question: how to auto-increment index field on INSERT?|