- Categories:
System functions (System Control)
SYSTEM$ADD_ REFERENCE¶
Called by a Snowflake Native App to associate a consumer reference string to a reference definition. The app can use this association to access the consumer object. The reference string passed to this system function is the value returned by the SYSTEM$REFERENCE function, which represents a consumer object.
For information about using this function in an app, see Request references and object-level privileges from consumers.
This function supports both single-valued and multi-valued references. For a single-valued reference, the function returns an error if an association already exists. To replace that association, use SYSTEM$SET_REFERENCE.
Syntax¶
Arguments¶
'reference_name'The name of the reference as specified in the
manifest.ymlfile of the app.'reference_string'The system-generated ID of the reference to the object in the consumer account.
Returns¶
Returns a VARCHAR value that contains the system-generated alias for the new association.
For a multi-valued reference, pass this alias to SYSTEM$REMOVE_REFERENCE
or SYSTEM$GET_REFERENCED_OBJECT_ID_HASH to identify a single association.
Examples¶
This example assumes that the app manifest defines a multi-valued consumer_tables reference
with object type TABLE and the SELECT privilege. The app’s setup script must also create
the config schema and app_admin application role and grant USAGE on the schema to that role.
For the manifest and setup-script prerequisites, see Request references and object-level privileges from consumers.
Add this procedure to the app’s setup script. It runs with the app’s privileges and returns the alias of the new association:
After installing the app as my_app, the consumer creates a persistent reference to an
existing table and passes it to the procedure. The consumer’s role must have the privileges
needed to create the reference and must be granted the my_app.app_admin application role:
The procedure returns a UUID alias, for example:
The alias is illustrative. Each association has its own system-generated alias. Repeat the
consumer statements with a different table to add another association to consumer_tables.