How can I find table name for each row result?
There must be some kind of misunderstanding. tableoid is a system column that's available for any regular table in any version of Postgres since at least v7.3. Per documentation:


  Every table has several system columns that are implicitly defined by the system.


tableoid is one of them. The solution I provided under the questions you refer to is also suggested in the manual here. And it works. I have been using it for years in various Postgres versions.

Either you are not using Postgres, or template is not a table. Is it a VIEW maybe? If you define a VIEW like:

CREATE VIEW template AS
SELECT * FROM some_table;


Then system columns are not included by default.

What do you get for

SELECT relnamespace, relname, relkind
FROM   pg_class
WHERE  relname = 'template';


Is relkind 'r', 'v' or something else?
Or do you get multiple rows? Then consider this:


Why does a PostgreSQL SELECT query return different results when a schema name is specified?