Format specifier for integer variables in format() for EXECUTE?

This would be shorter, faster and safer: CREATE OR REPLACE FUNCTION get_parent_ltree(parent_id bigint, tbl_name regclass , OUT parent_ltree ltree) LANGUAGE plpgsql AS $func$ BEGIN EXECUTE format(‘SELECT l_tree FROM %s WHERE id = $1′, tbl_name) INTO parent_ltree USING parent_id; END $func$; Why? Most importantly, use the USING clause of EXECUTE for parameter values. Don’t convert them … Read more

Efficiently repeat a character/string n times in Scala

For strings you can just write “abc” * 3, which works via StringOps and uses a StringBuffer behind the scenes. For characters I think your solution is pretty reasonable, although char.toString * n is arguably clearer. Do you have any reason to suspect the List.fill version isn’t efficient enough for your needs? You could write … Read more

Concatenating strings doesn’t work as expected [closed]

Your code, as written, works. You’re probably trying to achieve something unrelated, but similar: std::string c = “hello” + “world”; This doesn’t work because for C++ this seems like you’re trying to add two char pointers. Instead, you need to convert at least one of the char* literals to a std::string. Either you can do … Read more

const char* concatenation

In your example one and two are char pointers, pointing to char constants. You cannot change the char constants pointed to by these pointers. So anything like: strcat(one,two); // append string two to string one. will not work. Instead you should have a separate variable(char array) to hold the result. Something like this: char result[100]; … Read more