Catalin Catalin - 5 months ago 8
SQL Question

Regex put name schema for 'table' in select query syntax

How can I put with regex, schema name table, for query select?

Query doesn't have fixed size.

Example:

select * from t1 union select * from t2


Result:

select * from schema1.t1 union select * from schema1.t2


Thanks!

Answer

(1) If you are using it in a code, maybe you can do a search and replace at front end as Luk suggested.

(2) Alternatively, in your current session you can set default schema as schema1 so your query would work without schema name. But it would depend on your database name.

Like in Oracle you can do

ALTER SESSION SET CURRENT_SCHEMA=schema1

Now select * from t1 would effectively mean select * from schema1.t1.

You can search how to set default schema in <your database> in google and you would get syntax for other databases as well.

Comments