-- Regression tests for the PR 24 review findings owned by the engine3 group. -- Each case names its finding as R. SET client_min_messages = warning; CREATE EXTENSION IF NOT EXISTS plx; -- e3_err(q) runs q and returns 'SQLSTATE: message' if it fails. The message -- leaves out the error position, which differs between PostgreSQL 13 -- (plpgsql prefixes each expression with SELECT) and later versions. CREATE FUNCTION e3_err(q text) RETURNS text LANGUAGE plpgsql AS $h$ BEGIN EXECUTE q; RETURN 'no error'; EXCEPTION WHEN OTHERS THEN RETURN SQLSTATE || ': ' || SQLERRM; END $h$; -- R1: deeply nested brackets transpile in linear time (the ** rewriter used -- to scan each group to its end at every bracket, which took seconds here) SET statement_timeout = '1s'; SET check_function_bodies = off; DO $d$ BEGIN EXECUTE format('CREATE FUNCTION e3_r1_js() RETURNS text LANGUAGE plxjs AS %L', 'let a = 1; return ' || repeat('("x" + ', 16000) || 'a' || repeat(')', 16000) || ';'); END $d$; DO $d$ BEGIN EXECUTE format('CREATE FUNCTION e3_r1_ts() RETURNS int LANGUAGE plxts AS %L', 'let a: number = 1; return ' || repeat('(', 32000) || 'a' || repeat(')', 32000) || ';'); END $d$; DO $d$ BEGIN EXECUTE format('CREATE FUNCTION e3_r1_php() RETURNS int LANGUAGE plxphp AS %L', '$a = 1; return ' || repeat('[', 32000) || '$a' || repeat(']', 32000) || ';'); END $d$; DO $d$ BEGIN EXECUTE format('CREATE FUNCTION e3_r1_py() RETURNS int LANGUAGE plxpython3 AS %L', 'a = 1' || chr(10) || 'return ' || repeat('abs(', 24000) || 'a' || repeat(')', 24000)); END $d$; DO $d$ BEGIN EXECUTE format('CREATE FUNCTION e3_r1_rb() RETURNS int LANGUAGE plxruby AS %L', 'a = 1' || chr(10) || 'return ' || repeat('abs(', 24000) || 'a' || repeat(')', 24000)); END $d$; RESET check_function_bodies; RESET statement_timeout; -- the ** inside a group is still rewritten CREATE FUNCTION e3_r1_pow() RETURNS int LANGUAGE plxjs AS $$ return abs(((2 ** 3 ** 2)) - 0) + (1 + (2 ** 2)); $$; SELECT e3_r1_pow(); e3_r1_pow ----------- 517 (1 row) -- R6: nested loop labels that differ only in case are rejected (plpgsql -- would read both as one label, so continue Outer went to the inner loop) CREATE FUNCTION e3_r6_js() RETURNS int LANGUAGE plxjs AS $$ let s = 0; Outer: for (let i = 0; i < 3; i++) { outer: for (let j = 0; j < 3; j++) { if (j == 1) { continue Outer; } s += 1; } } return s; $$; ERROR: plxjs: identifiers "Outer" and "outer" are the same name to plpgsql, which ignores case HINT: Rename one of them. CREATE FUNCTION e3_r6_py() RETURNS int LANGUAGE plxpython3 AS $$ s = 0 Outer: for i in range(3): outer: for j in range(3): if j == 1: break Outer s += 1 return s $$; ERROR: plxpython3: identifiers "Outer" and "outer" are the same name to plpgsql, which ignores case HINT: Rename one of them. CREATE FUNCTION e3_r6_rb() RETURNS int LANGUAGE plxruby AS $$ s = 0 Outer: for i in 0..2 outer: for j in 0..2 break Outer if j == 1 s += 1 end end return s $$; ERROR: plxruby: identifiers "Outer" and "outer" are the same name to plpgsql, which ignores case HINT: Rename one of them. -- labels that differ only in case on loops that are not nested still work CREATE FUNCTION e3_r6_seq() RETURNS int LANGUAGE plxjs AS $$ let s = 0; Outer: for (let i = 0; i < 3; i++) { if (i == 1) { break Outer; } s += 1; } outer: for (let j = 0; j < 3; j++) { if (j == 2) { break outer; } s += 10; } return s; $$; SELECT e3_r6_seq(); e3_r6_seq ----------- 21 (1 row) -- R7: plxphp '.' works on a string built with '.=' (the builder local was -- passed to || as it is, which PostgreSQL could not resolve) CREATE TABLE e3_names(id int, name text); INSERT INTO e3_names VALUES (1, 'ann'), (2, 'bob'); CREATE FUNCTION e3_r7_sb2() RETURNS text LANGUAGE plxphp AS $body$ $s = "" /*:: text */; foreach (query("SELECT name FROM e3_names ORDER BY id") as $row) { $s .= $row->name; $s .= ","; } return "names: " . $s; $body$; SELECT e3_r7_sb2(); e3_r7_sb2 ----------------- names: ann,bob, (1 row) CREATE FUNCTION e3_r7_g10(n int) RETURNS text LANGUAGE plxphp AS $body$ $s = ""; $t = ""; for ($i = 0; $i < $n; $i++) { $s .= "x"; } $t = $s . "!"; return $t; $body$; SELECT e3_r7_g10(3); e3_r7_g10 ----------- xxx! (1 row) -- a read that comes before the first .= in the source CREATE FUNCTION e3_r7_early() RETURNS text LANGUAGE plxphp AS $body$ $s = ""; $out = ""; for ($k = 0; $k < 3; $k++) { $out = $out . "[" . $s . "]"; $s .= "x"; } return $out . $s; $body$; SELECT e3_r7_early(); e3_r7_early -------------- [][x][xx]xxx (1 row) -- R15: the second string append works whatever plx's schema is called. A -- schema name of 50 bytes or more overflowed the buffer is_builder_type -- copied the qualified type name into, so the local stopped counting as a -- string and s += 'b' became numeric addition. This case re-creates the -- extension in such schemas and puts it back in public at the end. DROP EXTENSION plx CASCADE; CREATE SCHEMA sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss; CREATE EXTENSION plx SCHEMA sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss; CREATE FUNCTION e3_r15_js_long() RETURNS text LANGUAGE plxjs AS $$ let s = ''; s += 'a'; s += 'b'; return s; $$; CREATE FUNCTION e3_r15_ts_long() RETURNS text LANGUAGE plxts AS $$ let s: string = ''; s += 'a'; s += 'b'; return s; $$; CREATE FUNCTION e3_r15_py_long() RETURNS text LANGUAGE plxpython3 AS $$ s = '' s += 'a' s += 'b' return s $$; CREATE FUNCTION e3_r15_rb_long() RETURNS text LANGUAGE plxruby AS $$ s = '' s << 'a' s << 'b' return s $$; SELECT e3_r15_js_long(), e3_r15_ts_long(), e3_r15_py_long(), e3_r15_rb_long(); e3_r15_js_long | e3_r15_ts_long | e3_r15_py_long | e3_r15_rb_long ----------------+----------------+----------------+---------------- ab | ab | ab | ab (1 row) DROP EXTENSION plx CASCADE; CREATE SCHEMA "Plx ""Q"" Schema With Mixed Case And Quotes """"x"""" 0123456789"; CREATE EXTENSION plx SCHEMA "Plx ""Q"" Schema With Mixed Case And Quotes """"x"""" 0123456789"; CREATE FUNCTION e3_r15_js_quoted() RETURNS text LANGUAGE plxjs AS $$ let s = ''; s += 'a'; s += 'b'; return s; $$; CREATE FUNCTION e3_r15_ts_quoted() RETURNS text LANGUAGE plxts AS $$ let s: string = ''; s += 'a'; s += 'b'; return s; $$; CREATE FUNCTION e3_r15_py_quoted() RETURNS text LANGUAGE plxpython3 AS $$ s = '' s += 'a' s += 'b' return s $$; CREATE FUNCTION e3_r15_rb_quoted() RETURNS text LANGUAGE plxruby AS $$ s = '' s << 'a' s << 'b' return s $$; SELECT e3_r15_js_quoted(), e3_r15_ts_quoted(), e3_r15_py_quoted(), e3_r15_rb_quoted(); e3_r15_js_quoted | e3_r15_ts_quoted | e3_r15_py_quoted | e3_r15_rb_quoted ------------------+------------------+------------------+------------------ ab | ab | ab | ab (1 row) DROP EXTENSION plx CASCADE; DROP SCHEMA sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss; DROP SCHEMA "Plx ""Q"" Schema With Mixed Case And Quotes """"x"""" 0123456789"; CREATE EXTENSION plx SCHEMA public; -- R5: a counting for whose variable is read after the loop, or again by an -- enclosing loop, is rejected when the read is inside a string -- interpolation too (it used to see the value from before the loop) CREATE FUNCTION e3_r5_rl1(n int) RETURNS text LANGUAGE plxjs AS $body$ let i = 0; for (i = 0; i < n; i++) { if (i * i > 10) { break; } } let r = fetch_one(`SELECT ${i} * 100 AS v`); return `first i with i*i > 10: ${i}, query says ${r.v}`; $body$; ERROR: plxjs: the loop variable "i" is read after the for loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxjs source line 3 CREATE FUNCTION e3_r5_rl2(n int) RETURNS text LANGUAGE plxjs AS $body$ let s = ""; let j = 0; let k = 0; while (k < 2) { s += `[j=${j}]`; for (j = 0; j < n; j++) { } k += 1; } return s; $body$; ERROR: plxjs: the loop variable "j" is read again by an enclosing loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxjs source line 5 CREATE FUNCTION e3_r5_rl3(n int) RETURNS text LANGUAGE plxphp AS $body$ $i = 0; for ($i = 0; $i < $n; $i++) { if ($i * $i > 10) { break; } } return "stopped at $i"; $body$; ERROR: plxphp: the loop variable "i" is read after the for loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxphp source line 3 CREATE FUNCTION e3_r5_ts(n int) RETURNS text LANGUAGE plxts AS $body$ let i: number = 0; for (i = 0; i < n; i++) { } return `${i}`; $body$; ERROR: plxts: the loop variable "i" is read after the for loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxts source line 3 -- a read in the header of an enclosing loop CREATE FUNCTION e3_r5_hdr(n int) RETURNS int LANGUAGE plxjs AS $body$ let j = 0; let k = 0; while (`${j}` != "3") { for (j = 0; j < n; j++) { } k += 1; } return k; $body$; ERROR: plxjs: the loop variable "j" is read again by an enclosing loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxjs source line 4 -- the name in plain text, or in a string that does not interpolate, is not a read CREATE FUNCTION e3_r5_plain(n int) RETURNS text LANGUAGE plxjs AS $body$ let i = 0; let t = 0; for (i = 0; i < n; i++) { t += i; } let name = "i"; return `${name} = ${t}`; $body$; SELECT e3_r5_plain(4); e3_r5_plain ------------- i = 6 (1 row) -- plxpython3 and plxruby already keep the final value, interpolation included CREATE FUNCTION e3_r5_py(n int) RETURNS text LANGUAGE plxpython3 AS $body$ i = 0 for i in range(n): if i * i > 10: break return f"stopped at {i}" $body$; SELECT e3_r5_py(100); e3_r5_py -------------- stopped at 4 (1 row) CREATE FUNCTION e3_r5_rb(n int) RETURNS text LANGUAGE plxruby AS $body$ i = 0 for i in 0...n break if i * i > 10 end return "stopped at #{i}" $body$; SELECT e3_r5_rb(100); e3_r5_rb -------------- stopped at 4 (1 row) -- R8: plxpython3 range() with a negative literal step counts down, as in -- Python (it used to fail with "BY value of FOR loop must be greater than zero") CREATE FUNCTION e3_r8_py4() RETURNS text LANGUAGE plxpython3 AS $body$ s = "" for k in range(10, 0, -3): s += f"{k}," return s $body$; SELECT e3_r8_py4(); e3_r8_py4 ----------- 10,7,4,1, (1 row) CREATE FUNCTION e3_r8_odd(n int) RETURNS text LANGUAGE plxpython3 AS $body$ s = "" for k in range(n, -1, -2): s += f"{k}," for k in range(0, 5, -1): s += "never" return s $body$; SELECT e3_r8_odd(5); e3_r8_odd ----------- 5,3,1, (1 row) -- the loop variable keeps its last value after the loop CREATE FUNCTION e3_r8_last() RETURNS int LANGUAGE plxpython3 AS $body$ k = 0 for k in range(10, 0, -3): pass return k $body$; SELECT e3_r8_last(); e3_r8_last ------------ 1 (1 row) -- V1 (review of the PR 24 fixes): an escaped \$i, \${i} or \#{i} is plain -- text, not an interpolation, so it is not a read of the loop variable. A SQL -- template treats the escape the same way as a string value does (it used to -- interpolate there, so "SELECT '\$i'" ran with the value of $i). CREATE FUNCTION e3_v1_php(n int) RETURNS text LANGUAGE plxphp AS $body$ for ($i = 0; $i < $n; $i++) { if ($i > 2) { break; } } $r = fetch_one("SELECT '\$i {\$i}' AS v"); return "esc \$i {\$i} " . $r['v']; $body$; SELECT e3_v1_php(5); e3_v1_php --------------------- esc $i {$i} $i {$i} (1 row) CREATE FUNCTION e3_v1_js(n int) RETURNS text LANGUAGE plxjs AS $body$ let i = 0; for (i = 0; i < n; i++) { if (i > 2) { break; } } let r = fetch_one(`SELECT '\${i}' AS v`); return `esc \${i} ${r.v}`; $body$; SELECT e3_v1_js(5); e3_v1_js --------------- esc ${i} ${i} (1 row) CREATE FUNCTION e3_v1_rb() RETURNS text LANGUAGE plxruby AS $body$ i = 5 r = fetch_one("SELECT '\#{i}' AS v") return "esc \#{i} #{r.v}" $body$; SELECT e3_v1_rb(); e3_v1_rb --------------- esc #{i} #{i} (1 row) -- in a plxpython3 f-string a backslash does not escape the brace, as in Python CREATE FUNCTION e3_v1_py() RETURNS text LANGUAGE plxpython3 AS $body$ i = 5 r = fetch_one(f"SELECT '\{i}' AS v") return r["v"] $body$; SELECT e3_v1_py(); e3_v1_py ---------- \5 (1 row) -- an escaped backslash before the interpolation does not escape it: still a read CREATE FUNCTION e3_v1_php_bs(n int) RETURNS text LANGUAGE plxphp AS $body$ for ($i = 0; $i < $n; $i++) { } return "bs \\$i"; $body$; ERROR: plxphp: the loop variable "i" is read after the for loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxphp source line 2 -- V2 (review of the PR 24 fixes): a field with the loop variable's name, as -- in ${r.i}, is not a read of the loop variable CREATE FUNCTION e3_v2_js(n int) RETURNS text LANGUAGE plxjs AS $body$ let i = 0; for (i = 0; i < n; i++) { } let r = fetch_one("SELECT 5 AS i"); return `${r.i}`; $body$; SELECT e3_v2_js(3); e3_v2_js ---------- 5 (1 row) CREATE FUNCTION e3_v2_ts(n int) RETURNS text LANGUAGE plxts AS $body$ let i: number = 0; for (i = 0; i < n; i++) { } let r = fetch_one("SELECT 6 AS i"); return `${r.i}`; $body$; SELECT e3_v2_ts(3); e3_v2_ts ---------- 6 (1 row) -- the variable itself beside the field is still a read CREATE FUNCTION e3_v2_js_both(n int) RETURNS text LANGUAGE plxjs AS $body$ let i = 0; for (i = 0; i < n; i++) { } let r = fetch_one("SELECT 5 AS i"); return `${r.i + i}`; $body$; ERROR: plxjs: the loop variable "i" is read after the for loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxjs source line 3 -- R2-C10 (PR 24 review r2 c1[0]): an exclusive loop bound becomes (HI) - 1 or -- (HI) + 1. The bound is parenthesized, because SQL binds + and - tighter than -- << >> & | #, so n >> 1 - 1 would be n >> 0. CREATE FUNCTION r2c10_js(n int) RETURNS text LANGUAGE plxjs AS $$ let s = ''; for (let i = 0; i < n >> 1; i++) { s += `${i} `; } for (let i = 0; i < n << 1; i += 3) { s += `${i};`; } return s; $$; CREATE FUNCTION r2c10_ts(n int) RETURNS text LANGUAGE plxts AS $$ let s: string = ''; for (let i = 0; i < n >> 1; i++) { s += `${i} `; } return s; $$; CREATE FUNCTION r2c10_php(n int) RETURNS text LANGUAGE plxphp AS $$ $s = ""; for ($i = 0; $i < $n >> 1; $i++) { $s .= "$i "; } return $s; $$; CREATE FUNCTION r2c10_py(n int) RETURNS text LANGUAGE plxpython3 AS $$ s = '' for i in range(n >> 1): s += f"{i} " for i in range(n, n >> 1, -1): s += f"{i}," for i in range(10, n | 1, -2): s += f"{i};" return s $$; CREATE FUNCTION r2c10_rb(n int) RETURNS text LANGUAGE plxruby AS $$ s = '' for i in 0...n >> 1 s << "#{i} " end (0...n & 6).each do |j| s << "#{j}," end return s $$; SELECT r2c10_js(6) AS js, r2c10_ts(6) AS ts, r2c10_php(6) AS php, r2c10_py(6) AS py, r2c10_rb(6) AS rb; js | ts | php | py | rb ----------------+--------+--------+-------------------+-------------------- 0 1 2 0;3;6;9; | 0 1 2 | 0 1 2 | 0 1 2 6,5,4,10;8; | 0 1 2 0,1,2,3,4,5, (1 row) -- js: 0 1 2 0;3;6;9; ts: 0 1 2 php: 0 1 2 py: 0 1 2 6,5,4,10;8; rb: 0 1 2 0,1,2,3,4,5, -- R2-C12 (PR 24 review r2 c1[2]): a string local that an append turns into -- the string builder is read as text in every dialect, so || and an -- interpolation into SQL work on it (review [7] fixed plxphp only). -- A numeric += local is still read as a number. CREATE FUNCTION r2c12_js() RETURNS text LANGUAGE plxjs AS $$ let s = ''; s += 'a'; s += 'b'; let n = 1; n += 2; let r = fetch_one(`SELECT ${s} || '?' AS v`); return `${s || '!'}${r.v}${n + 1}`; $$; CREATE FUNCTION r2c12_ts() RETURNS text LANGUAGE plxts AS $$ let s: string = ''; s += 'a'; s += 'b'; let r = fetch_one(`SELECT ${s} || '!' AS v`); return r.v; $$; CREATE FUNCTION r2c12_rb() RETURNS text LANGUAGE plxruby AS $$ s = '' s << 'a' s << 'b' return s || '!' $$; CREATE FUNCTION r2c12_py() RETURNS text LANGUAGE plxpython3 AS $$ s = '' s += 'a' s += 'b' n = 1 n += 2 r = fetch_one(f"SELECT {s} || '!' AS v, {n} + 1 AS m") return f"{r.v}{r.m}" $$; SELECT r2c12_js() AS js, r2c12_ts() AS ts, r2c12_rb() AS rb, r2c12_py() AS py; js | ts | rb | py ---------+-----+-----+------ ab!ab?4 | ab! | ab! | ab!4 (1 row) -- js: ab!ab?4 ts: ab! rb: ab! py: ab!4 -- R2-C13 (PR 24 review r2 c1[3]): in plxphp "\{$x}", \{ is no escape and -- the { opens no {$...}: PHP keeps the backslash and the braces and -- interpolates $x. The same holds in a string value, in static SQL and in -- dynamic SQL. CREATE FUNCTION r2c13_php(x int) RETURNS text LANGUAGE plxphp AS $$ $r = fetch_one("SELECT 'sql=\{$x}' AS v"); $d = fetch_one("SELECT 'dyn=\{$x}' || $1 AS v", '!'); return "str=\{$x} " . $r->v . " " . $d->v; $$; SELECT r2c13_php(5) AS r; -- PHP: str=\{5} sql=\{5} dyn=\{5}! r ----------------------------- str=\{5} sql=\{5} dyn=\{5}! (1 row) -- R2-S10 (PR 24 review r2 s1[0]): the check that a counting-for variable is -- not read after the loop scanned from each loop to the end of the body, so -- CREATE FUNCTION took time quadratic in the number of loops (16,000 loops -- and a string naming every variable: about 10 s; 2.0.1: 0.06 s). It now -- skips the scan for a name that does not occur after the loop. SET statement_timeout = '3s'; DO $d$ BEGIN EXECUTE format('CREATE FUNCTION r2s10_php() RETURNS int LANGUAGE plxphp AS %L', (SELECT string_agg(format('for ($i%s = 0; $i%s < 1; $i%s++) { }', k, k, k), E'\n') FROM generate_series(1, 16000) k) || E'\n$s = "' || (SELECT string_agg('i' || k, ' ') FROM generate_series(1, 16000) k) || E'";\nreturn 1;'); END $d$; RESET statement_timeout; SELECT r2s10_php() AS r; -- 1 r --- 1 (1 row) -- the check still sees a read after the loop CREATE FUNCTION r2s10_read() RETURNS text LANGUAGE plxphp AS $$ for ($i = 0; $i < 3; $i++) { } return "i=$i"; $$; ERROR: plxphp: the loop variable "i" is read after the for loop, but a counting for does not keep its final value; use a while loop DETAIL: at plxphp source line 2 -- R3-C30 (PR 24 review r3 s1[1]): a string builder (a += or << target) is -- read as (s)::text, but a record field with the same name, r.s, was -- rewritten too, to r.(s)::text, a syntax error at CREATE FUNCTION. -- 2.0.1 returned the field. CREATE FUNCTION r3c30_js() RETURNS text LANGUAGE plxjs AS $$ let s = ''; s += 'a'; let r = fetch_one(`SELECT 'X' AS s`); return `${r.s}${s}`; $$; SELECT r3c30_js() AS r; -- Xa r ---- Xa (1 row) CREATE FUNCTION r3c30_ts() RETURNS text LANGUAGE plxts AS $$ let s: string = ''; s += 'a'; let r = fetch_one(`SELECT 'X' AS s`); return `${r.s}${s}`; $$; SELECT r3c30_ts() AS r; -- Xa r ---- Xa (1 row) CREATE FUNCTION r3c30_py() RETURNS text LANGUAGE plxpython3 AS $$ s = '' s += 'a' r = fetch_one("SELECT 'X' AS s") return f"{r.s}{s}" $$; SELECT r3c30_py() AS r; -- Xa r ---- Xa (1 row) CREATE FUNCTION r3c30_rb() RETURNS text LANGUAGE plxruby AS $$ s = '' s << 'a' r = fetch_one("SELECT 'X' AS s") return r.s $$; SELECT r3c30_rb() AS r; -- X r --- X (1 row) -- R3-F30 (PR 24 review r3): in plxjs, plxts and plxphp, < binds tighter -- than & and ^, so i < n & 6 is (i < n) & 6 (PHP 8.5: 0 iterations for -- n = 6), but the loop was lowered with the bound (n & 6) (6 iterations). -- A bound with & or ^ outside brackets is now rejected, as | already was. CREATE FUNCTION r3f30_php(n int) RETURNS int LANGUAGE plxphp AS $$ $c = 0; for ($i = 0; $i < $n & 6; $i++) { $c = $c + 1; } return $c; $$; ERROR: plxphp: for-loop bound must be a single value, not a condition; use a while loop DETAIL: at plxphp source line 3 CREATE FUNCTION r3f30_js(n int) RETURNS int LANGUAGE plxjs AS $$ let c = 0; for (let i = 0; i < n ^ 1; i++) { c = c + 1; } return c; $$; ERROR: plxjs: for-loop bound must be a single value, not a condition; use a while loop DETAIL: at plxjs source line 3 -- in brackets the bound is one value CREATE FUNCTION r3f30_ok(n int) RETURNS int LANGUAGE plxjs AS $$ let c = 0; for (let i = 0; i < (n & 6); i++) { c = c + 1; } return c; $$; SELECT r3f30_ok(7) AS r; -- 6 r --- 6 (1 row) -- R4-C40 (PR 24 review r4): the R3-C30 check looked only at the character -- right before the name, so r . s (spaces around the dot, valid in Ruby, -- Python and JS) still became r . (s)::text. 2.0.1 returned the field. CREATE FUNCTION r4c40_rb() RETURNS text LANGUAGE plxruby AS $$ s = "a" s << "b" r = fetch_one("SELECT 'F'::text AS s") return r . s $$; SELECT r4c40_rb() AS r; -- F r --- F (1 row) CREATE FUNCTION r4c40_py() RETURNS text LANGUAGE plxpython3 AS $$ s = "a" s += "b" r = fetch_one("SELECT 'F'::text AS s") return r . s $$; SELECT r4c40_py() AS r; -- F r --- F (1 row)