Question
· 21 hr ago

Do I need a separate python iris connection for each Namespace?

Or can I change namespaces within one connection object?

Product version: IRIS 2024.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1.2 (Build 398_0_23819) Wed Nov 20 2024 18:24:21 EST [Health:7.0.3]
Discussion (4)5
Log in or sign up to continue

Yes, it is possible to change namespaces within a single connection object. This can be done in ObjectScript using the $NAMESPACE or $ZNSPACE special variables, or by using commands such as ZNSPACE or SET $NAMESPACE. These methods allow temporarily switching the current namespace, either for the duration of the routine or programmatically as needed.

When changing namespaces programmatically, the recommended approach is to use NEW $NAMESPACE followed by SET $NAMESPACE, which ensures that the namespace automatically reverts when the routine concludes or an unexpected error occurs. This prevents issues that may arise from leaving the namespace context inappropriately changed [1][2][3].

For additional control or safety when switching back to the previous namespace, you can store the original namespace, perform your operations in the desired namespace, and explicitly return to the original one using SET $NAMESPACE=<PreviousNamespace> [3][2].

Changing namespaces programmatically in application code should usually be avoided unless strictly necessary, as it may have performance implications and could introduce errors in handling objects or SQL cursors if they span across namespaces. For application-specific functionality, other practices such as global mappings or methods in separate productions might be more suitable [1][3][2].

Sources: