Can we pass a varchar/text datatype in to a variable in pgbench? --pgbench sql script

[pg93@db1 load_test]$ cat get_email.sql 
\setrandom cnt 1 100000
\set v_username 'user_' || :cnt

begin;
select get_user_email(:v_username);
end;


get_user_email() is a function which can get user's email.

--pgbench

[pg93@db1 load_test]$ nohup pgbench -c 4 -T 10 -d proxy -U proxy  -N -n -f get_email.sql  &gt;  get_email.out  2&gt;&amp;1 &amp;


--the get_email.out file says

nohup: ignoring input
client 0 executing \setrandom cnt 1 100000
client 0 executing \set v_username 'user_' || :cnt
invalid input syntax for integer: "'user_'"
invalid input syntax for integer: "'user_'"
set: unsupported operator ||


It's seem that can only use integer datatype.

--data

db2=&gt; select * from users limit 3;
 username |      email      
----------+-----------------
 user_6   | user_6@163.com
 user_19  | user_19@163.com
 user_20  | user_20@163.com


get_user_email() is a function which can get user's email.
According to the documentation, pgbench variables are supposed to be boolean, integer, float, or variable-references.

However it appears to be possible to pass arbitrary text to --define so long as you don't try to use pgbench operators that will treat it as a numeric value.

pgbench doesn't support psql-style :'quoted_variable' syntax for literals or :"quoted_variable" for identifiers. So you have to quote the value you pass.

e.g. if you invoke pgbench with --define "v_username='fred'" then the variable's string value will be 'fred', including the quotes. You can then write:

\setrandom cnt 1 100000

begin;
select get_user_email('user_' || :v_username);
end;


Note that the concatenation is done in SQL, as pgbench expression language doesn't have string operators.