Question: Just for learning purposes, I'm trying to create a function using PLPGSQL and make an SQL injection on it. I recently learned about `format`, `USING` and `quote_literal` and `quote_indent`, so I'm good about avoiding an SQL injection. What I'm trying to do is create a function that allows an SQL injection (i.e. a `drop table`).

So I wrote this:

```
create or replace function badfunc(tablename text, identifier int4)
returns setof character varying as $$
declare
    query text;
begin
    query := 'select full_name from ' || $1 || ' where re = ' || $2 ||'';
    raise notice 'query: %', query;
    return query execute query;
end;
$$ language 'plpgsql';

```

But when I execute this function with `select badfunc('; drop table tb_students;', 1001);` I get this error:

```
[42601] ERROR: syntax error at or near ";" where: function PL/pgSQL badfunc(text,integer) linha 7 in RETURN QUERY

```

So I think that's not how it is done. How can I achieve this SQL injection?

Answer: 
It seems you are going to restore a database which does not exists in backup set. To see what is the logical name of database in the backup set:

```
RESTORE FILELISTONLY   
FROM DISK = 'filename.bak' 

```
A colleague has provided me with a solution: simply create another SQL-server server. I don't know the exact tool he used for doing that, but the result in the Microsoft SQL-server Management Studio looks as follows:

[![enter image description here](https://i.stack.imgur.com/2dDG6.png)](https://i.stack.imgur.com/2dDG6.png)