pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Function returns error
2+ messages / 2 participants
[nested] [flat]

* Function returns error
@ 2004-06-10 15:01 Michael Long <mlong@datalong.com>
  2004-06-10 15:38 ` Re: Function returns error Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Michael Long @ 2004-06-10 15:01 UTC (permalink / raw)
  To: pgsql-sql

Hi All,

I am a relatively new user to postgres. I have created a function that compiles but
generates an error when executed. I know I am overlooking something simple. The
function and error are below.

CREATE OR REPLACE FUNCTION building_insert(varchar, int4, varchar)
  RETURNS int4 AS
'

/* Return code dictionary:
        0 - Success
        1 - Valid User, Insert Failed
        2 - Invalid User, Abort
*/
DECLARE
        p_user ALIAS FOR $1;
        p_parcel_id ALIAS FOR $2;
        p_name ALIAS FOR $3;

BEGIN

        IF p_user == \'mlong\' THEN
                RETURN 2;
        END IF;

        INSERT  INTO
		building(
			parcel_id,
			name,
			createdate
		)
	VALUES(
			p_parcel_id,
			p_name,
  			now()
		);


        RETURN 0;
END;
' LANGUAGE 'plpgsql' VOLATILE;

/* Query that generates error */
select building_insert('mlong', 20,'building 1');

ERROR:  operator does not exist: character varying == "unknown"
HINT:  No operator matches the given name and argument type(s). You may need to add
explicit type casts.
CONTEXT:  PL/pgSQL function "building_insert" line 14 at if

Thanks,
Mike



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Function returns error
  2004-06-10 15:01 Function returns error Michael Long <mlong@datalong.com>
@ 2004-06-10 15:38 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2004-06-10 15:38 UTC (permalink / raw)
  To: mlong@datalong.com; +Cc: pgsql-sql

Michael Long wrote:
> ERROR:  operator does not exist: character varying == "unknown"
> HINT:  No operator matches the given name and argument type(s). You may need to add
> explicit type casts.
> CONTEXT:  PL/pgSQL function "building_insert" line 14 at if

Common mistake, still make it myself on occasion. The '==' operator 
doesn't exist in plpgsql, you should use '=' when comparing and ':=' for 
assignment.

HTH
-- 
   Richard Huxton
   Archonet Ltd



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-06-10 15:38 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-06-10 15:01 Function returns error Michael Long <mlong@datalong.com>
2004-06-10 15:38 ` Richard Huxton <dev@archonet.com>

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