From: | Domingo Alvarez Duarte <domingo(at)dad-it(dot)com> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | maybe a bug in plpgsql, nulls and empty strings are not the same |
Date: | 2001-05-27 17:00:37 |
Message-ID: | 3B1132B5.418D53C7@dad-it.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
When trying write a function in plpgsql I'm getting behavior that
probably isn't the corect one.
in the function bellow:
-----
-- split the given key
create function dad_char_key_split(
varchar, -- char_key
integer, -- subkey_len
char -- separator
) returns varchar as '
declare
p_char_key alias for $1;
p_subkey_len alias for $2;
p_separator alias for $3;
v_key_len integer;
v_from integer;
v_result varchar;
v_sep char;
begin
v_result := '''';
v_sep := '''';
v_from := 1;
v_key_len := char_length(p_char_key);
for i in 1..(v_key_len/p_subkey_len) loop
v_result := v_result || v_sep ||
substr(p_char_key,v_from,p_subkey_len);
v_sep := p_separator;
v_from := v_from + p_subkey_len;
end loop;
return v_result;
end;' language 'plpgsql';
----
if I try this:
select dad_char_key_split('00kjoi',2,',');
I get this result:
",kj,oi"
And when I change the initialization of the variables "v_sep" and
"v_result" from empty strings to a space ('' '' istead of '''') I get
the expected result:
"00,kj,oi"
It seems that plpgsql treats empty strings as null so when concatenating
with a empty string we get null instead of some value.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2001-05-27 17:11:36 | Re: New/old style trigger API |
Previous Message | D'Arcy J.M. Cain | 2001-05-27 14:56:13 | New/old style trigger API |