-1

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!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Catalin
  • 253
  • 8
  • 21
  • SQL is not a regular language, therefore it cannot be parsed by regular expressions. see e.g. http://stackoverflow.com/questions/26595394/what-kind-of-languge-is-sql – king_nak Jun 03 '16 at 10:20
  • Do you really need regex for this? You could just replace "from " to "from schema1." – LukStorms Jun 03 '16 at 10:20

1 Answers1

0

(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.

Utsav
  • 7,914
  • 2
  • 17
  • 38