[SQL] Function returns error

2004-06-10 Thread Michael Long
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

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] best way to swap two records (computer details)

2005-03-23 Thread Michael Long
> On Friday 18 March 2005 4:32 pm, you wrote:
>> How about a user defined function ???
>>
>> CREATE OR REPLACE FUNCTION harwareupdate(integer, integer) RETURNS
>> BOOLEAN AS '
>>
>> update pieces set p_name = \'LSALES1\', p_location = \'Mike
>> Haley\', p_site = \'L\' where p_id = $1;
>>
>> update pieces set p_name = \'SPARE\', p_location = \'spare\',
>> p_site = \'L\'
>> where p_id = 2;
>>
>

Why not declare variables and select the current values into them and then 
update
the records with the appropriate values.


---(end of broadcast)---
TIP 3: if posting/reading through Usenet, please send an appropriate
  subscribe-nomail command to [EMAIL PROTECTED] so that your
  message can get through to the mailing list cleanly