pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jasen Betts <jasen@xnet.co.nz>
To: pgsql-sql@postgresql.org
Subject: Re: very frustrating feature-bug
Date: 17 Feb 2010 10:51:04 GMT
Message-ID: <hlghmo$3g2$2@reversiblemaps.ath.cx> (raw)
References: <4B7B98AF.9050202@bankir.ru>

On 2010-02-17, silly sad <sad@bankir.ru> wrote:
>
> acc=>
>
> CREATE OR REPLACE FUNCTION add_user (TEXT, TEXT, TEXT, TEXT)
> RETURNS usr AS $$
>    INSERT INTO usr (login,pass,name,email) VALUES ($1,$2,$3,$4)
>    RETURNING usr.*;
> $$ LANGUAGE sql SECURITY DEFINER;
>
> acc=>
>
> ERROR:  return type mismatch in function declared to return usr
> DETAIL:  Function's final statement must be a SELECT.
> CONTEXT:  SQL function "add_user"
>
> SURPRISE :-) SURPRISE :-)

SQL functions are inlined when invoked, and so must be valid subselects.

rewrite it in plpgsql.

 CREATE OR REPLACE FUNCTION add_user (TEXT, TEXT, TEXT, TEXT)
 RETURNS usr AS $$
 DECLARE
   retval usr;
 BEGIN
    INSERT INTO usr (login,pass,name,email) VALUES ($1,$2,$3,$4)
    RETURNING usr.* INTO retval;
    RETURN retval;
 END;
 $$ LANGUAGE PLPGSQL SECURITY DEFINER;




view thread (6+ messages)  latest in thread

Message-ID: <hlghmo$3g2$2@reversiblemaps.ath.cx>
Permalink:  ../hlghmo$3g2$2@reversiblemaps.ath.cx/
Also on:    postgresql.org/message-id/hlghmo$3g2$2@reversiblemaps.ath.cx

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jasen@xnet.co.nz
  Subject: Re: very frustrating feature-bug
  In-Reply-To: <hlghmo$3g2$2@reversiblemaps.ath.cx>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox