DEFINE PARAM
statementThe DEFINE PARAM
statement allows you to define global (database-wide) parameters that are available to every client.
DEFINE PARAM
statement.DEFINE PARAM
statement.
SurrealQL SyntaxDEFINE PARAM [ OVERWRITE | IF NOT EXISTS ] $@name VALUE @value [ COMMENT @string ]
Below shows how you can create a parameter using the DEFINE PARAM
statement.
DEFINE PARAM $endpointBase VALUE "https://dummyjson.com";
Then, simply use the global parameter like you would with any variable.
RETURN http::get($endpointBase + "/products");
IF NOT EXISTS
clauseAvailable since: v1.3.0
The IF NOT EXISTS
clause can be used to define a param only if it does not already exist. You should use the IF NOT EXISTS
clause when defining a param in SurrealDB if you want to ensure that the param is only created if it does not already exist. If the param already exists, the DEFINE PARAM
statement will return an error.
It’s particularly useful when you want to safely attempt to define a param without manually checking its existence first.
On the other hand, you should not use the IF NOT EXISTS
clause when you want to ensure that the param definition is updated regardless of whether it already exists. In such cases, you might prefer using the OVERWRITE
clause, which allows you to define a param and overwrite an existing one if it already exists, ensuring that the latest version of the param definition is always in use
-- Create a PARAM if it does not already exist DEFINE PARAM IF NOT EXISTS $example VALUE 123;
OVERWRITE
clauseAvailable since: v2.0.0
The OVERWRITE
clause can be used to define a param and overwrite an existing one if it already exists. You should use the OVERWRITE
clause when you want to modify an existing param definition. If the param already exists, the DEFINE PARAM
statement will overwrite the existing param definition with the new one.
-- Create an PARAM and overwrite if it already exists DEFINE PARAM OVERWRITE $example VALUE 123;