Web Performance In Hindi : Website Performance Kya Hai?
Snowflake Virtual warehouses In Hindi | Create warehouse In Snowflake In Hindi
Time Travel In Snowflake In Hindi | Snowflake Time Travel Example
aws s3 kya hai ? | what is aws s3
AWS S3-Snowflake Pipeline Example | Snowflake Tutorials In Hindi
grep Command in Linux : What is grep Command ?
PHP Null Coalescing Operator In Hindi , Null Coalescing Operator kya hai ?
What is DNS In Hindi ? DNS kya hai?
Computer Basic Knowledge in Hindi
Bubble Sort in PHP With Example | How Bubble Sort Works in PHP
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
आपने SQL में कई सारे built in functions जैसे avg(), sum() , count(), max(), min() use किये होंगे , लेकिन snowflake में आपने custom functions को भी UDFs (User Defined Functions) कहते हैं।
Snowflake में UDFs (User Defined Functions) , आपके द्वारा लिखे गए custom functions हैं जो SQL queries
में callable होते हैं। मतलब इनकी returned value को SQL queries में use कर सकते हैं।
●●●
UDF को define करने का तरीका almost Snowflake Procedure की तरह ही same होता है। हालंकि Procedure और UDFs
में काफी difference है जो आगे देखेंगे।
Snowflake में आप SQL , SCALA , JAVA , Python , JavaScript programming languages में भी UDFs
define कर सकते हैं।
normally SQL syntax कुछ इस तरह से होता है।
CREATE [ OR REPLACE ] [ { TEMP | TEMPORARY } ] [ SECURE ] FUNCTION name ( [ arg_name arg_data_type ...) [ COPY GRANTS ] RETURNS { result_data_type | TABLE ( col_name col_data_type ) } [ [ NOT ] NULL ] [ { VOLATILE | IMMUTABLE } ] [ MEMOIZABLE ] [ COMMENT = 'string_literal' ] AS 'function_definition'
अब अगर आपको UDF
के अंदर variables define करने हैं तो आप DECLARE
statements का use कर सकते हैं।
For Example
CREATE OR REPLACE FUNCTION function_name(param1 VARCHAR, param2 INT) RETURNS VARCHAR LANGUAGE SQL AS $$ -- Declare variables DECLARE var1 INT; var2 VARCHAR; BEGIN -- Set values to variables var1 := 10; var2 := 'Example'; -- Use variables in SQL statements END; $$;
ये normal SQL
syntax था , हालाँकि Languages के according कुछ options काम या ज्यादा हो सकते हैं। और इन्ही options का use करके आप useful UDF define कर सकते है।
UDFs में return statement required होता है , मतलब function कुछ return करना ही चाहिए। SQL language के साथ आपको return keyword का use नहीं करना पड़ता है। बाकी programming language के साथ return keyword लिखना पड़ेगा।
तो बसे पहले हम एक simple UDF
example देखते हैं जो एक parameter को accept करेगा और जिसमे हम किसी user का नाम print करेंगे।
-- list user defined functions.
show user functions;
-- now create an UDF.
CREATE or replace FUNCTION greeting(name string)
RETURNS string
AS
$$
'Welcome to snowflake ' || name
$$;
-- list again.
show user functions;
हमने string parameter के साथ greeting()
नाम का function define किया है। अब इसे आप कितन बार भी call
करके use में ले सकते हैं।
●●●
select greeting('Babu Rao');
+-------------------------------+ | GREETING('BABU RAO') | |-------------------------------| | Welcome to snowflake Babu Rao | +-------------------------------+
Call again
select greeting('Raju');
Output
+---------------------------+ | GREETING('RAJU') | |---------------------------| | Welcome to snowflake Raju | +---------------------------+
●●●
अब same example को JavaScript Programming language का use करके देख लेते हैं।
CREATE or replace FUNCTION greeting_js(name string)
RETURNS string
language JavaScript
AS
$$
return 'Welcome to snowflake ' + NAME
$$;
function को call करने का तरीका same ही है।
select greeting('Raju');
Output
+---------------------------+ | GREETING('RAJU') | |---------------------------| | Welcome to snowflake Raju | +---------------------------+
इसी तरह से आप अपनी need के according UDFs को define करके SQL queries
में use कर सकते हैं।
●●●
UDF & Stored Procedure दोनों का structure लगभग एक जैसा है हालाँकि इनमे कुछ differences हैं -
Features | UDFs | Stored Procedures |
Part of SQL query | ✔ | ✖ |
Ability of overload | ✔ | ✔ |
One or more input parameters | ✔ | ✔ |
Can use JavaScript API | ✖ | ✔ |
Return value optional | ✖ | ✔ |
Called Itself recursively | ✖ | ✔ |
returned value is usable in SQL | ✔ | ✖ |
Reusable code : SQL queries में bar-bar logic को लिखने से बचने के लिए।
Complex logic : SQL में natively available नहीं होने वाली functionality को define करके use में लेने के लिए।
Performance optimization : Computationally expensive operations को database server पर nearly offload करने के लिए।
●●●
Stored procedures in snowflake
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook