Birt/Set Schema and Set Path - db2

I'm currently using a schema that will be changed to another schema in a couple of months. I do not not want to have to remove the SCHEMA_NAME multiple times from each report. All the reports so far have this format:
SELECT
COLUMN_NAME1,
SCHEMA_NAME.USER_DEFINED_FUNCTION(COLUMN_NAME2),
COLUMN_NAME3
FROM
SCHEMA_NAME.TABLE_NAME
I want to remove the schema name from the query so it looks like this:
SET SCHEMA LROUIM;
SET PATH LROUIM;
SELECT
COLUMN_NAME1,
USER_DEFINED_FUNCTION(COLUMN_NAME2),
COLUMN_NAME3
FROM
TABLE_NAME
I need the "SET SCHEMA" for the table name and "SET PATH" for the User Defined Function. This code works in Squirrel SQL, but if I insert this code into a Birt data set of type SQL SELECT QUERY, I get an error because of
SET SCHEMA LROUIM;
SET PATH LROUIM;
How do I implement SET SCHEMA and SET PATH in a SQL Select Query in Birt?

I think BIRT uses a JDBC connexion, and you can modify the connection parameters by specifying a default schema.

Related

Accessing table without using schema name

I am new with DB2.
I am not able to get data from a table without using the schema name. If I use a schema name with table name, I am able to fetch data.
Example:
SELECT * FROM TABLE_NAME;
It is giving me error, while
SELECT FROM SCHEMA_NAME.TABLE_NAME;
is fetching a result.
What do I have to set up not to always have to use the schema name?
By default, your username is used as the schema name for unqualified object names. You can see the current schema with, e.g. VALUES CURRENT SCHEMA. You can change the current schema for you current session with SET SCHEMA new_schema_name, or via e.g. a JDBC connection parameter. Most query tools also have a place to specify/change the current schema.
See the manual page for SET SCHEMA https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0001016.html
The full rules for the qualification of unqualified objects is here https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000720.html#r0000720__unq-alias
E.g.
Unqualified alias, index, package, sequence, table, trigger, and view names are implicitly qualified by the default schema.
However, you can create a public alias for a table, module or sequence if you wish to be able to reference it regardless of your CURRENT SCHEMA value.
https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0000910.html
(P.S. all the above assumes you are using Db2 LUW)
Try using SET SCHEMA to set the default schema to be used in the session:
SET SCHEMA SCHEMA_NAME;
SELECT * FROM TABLE_NAME;
When using DBeaver - right click on connection > Connection Settings > Initialization, and select your default DB and default Schema:
After that, open your SQL Script and select Active DB:

IBM Data Studio Table name issue

When I create a new SQL script , for example
select * from table
When I execute this the sql that gets ran is
SELECT * FROM MYNAME.TABLE
I understand DB2 does this , but I want the schema name to be concatenated onto the table names, not my username.
SELECT * FROM SCHEMANAME.TABLE
It did this for me before, but I dont know what changed that it now only puts the database username at the end of the tables.
Does anyone know how to set it so the schema name gets added on?
Best way in my eyes for Data Stuio is setting the special register "Current schema" on the Special Registers tab of the SQL Editor. Here is a screenshot
Schema name defaults to your authorisation ID (user name in most cases). To use a different name to qualify unqualified object names, set the special register CURRENT_SCHEMA appropriately:
SET SCHEMA whatever
Could you try this;
In Data Project Explorer,
right clicked, properties
Driver properties
type your schema in Default schema
disconnect and reconnect database;
and try without SCHEMANAME.

Passing schema name as parameter in db2 - unix

I have one stored proc in db2 (luw) on schema A which looks like below.
CREATE PROCEDURE A.GET_TOTAL (IN ID CHARACTER(23))
BEGIN
DECLARE CURSOR1 CURSOR WITH HOLD WITH RETURN TO CLIENT FOR
SELECT * FROM B.employee e where e.id=ID
END
Given sproc which exist on schema "A" runs query on another schema "B". This another schema name B may changed based on application logic. How can i pass the schema name as parameter to this sproc?
First, I do not think that stored procedure works because the select statement is not defined in a cursor or a prepared statement.
If you want to execute a dynamic SQL in a stored procedure, you need to define in a stmt, then prepare it and execute it.
Let's suppose you pass the schema name as parameter; If you want to change the schema, you can execute dynamically "set current schema" or concatenate the schema name in your query.
For more information: http://www.toadworld.com/platforms/ibmdb2/w/wiki/7461.prepare-execute-and-parameter-markers.aspx

How to include schema inf while using dblink in PostgreSQL?

All
I am trying to use dblink in PostgreSQL to run query on different databases. The following works if the table "user" is under the public schema:
select * from dblink(
'hostaddr=1.2.3.4 port=5434 dbname=dbname user=username password=password',
'select id from user')
as t1(
id bigint
);
However, I need to run the query on some other defined schemas. Does anyone know how to add the schema information in the above query? I can't figure it out from the PostgreSQL docs.
When you write SQL query like
SELECT id FROM user
PostgreSQL will resolve table name like user into fully qualified name like schema.tablename using schema search path, which by default is set to "$user",public.
In other words, user will resolve into public.user unless you tweaked server configuration.
However, you can specify schema explicitly in your statement, like this:
SELECT id FROM otherschema.user

Can you set default Schema for SQL 2008 Query

I have a schema called application. Is there a way that, rather than using the syntax
SELECT * FROM application.table
I can set the default schema so that I can just use
SELECT * FROM table
It would be the same idea as a using statement I suppose.
The default schema for all sql server users is "dbo", You can alter the default schema for a user by using commands ALTER USER
ALTER USER UserName WITH DEFAULT_SCHEMA = application;
It will be great to have a use statement for schemas.
You can vote the feature suggestion on Microsoft connect.