Saturday , November 23 2024

PostgreSQL Functions

In this section, we will understand the operation of PostgreSQL functions and learn how to use the function.

Like operations in programming languages, user-defined operations in PostgreSQL are plpgsql commands that accept parameters, perform an operation such as a complex calculation, and return the result of this operation as a value.

The return value can be a single scaler value or a result set.

In functions, unlike procedures, call is called as the select function name, not as “select*from view_adi”.

For example, let’s write a function called “sayitoplama” that gives the sum of two numbers entered as parameters.

Let’s talk a little about our function mentioned above.

create function sayitoplama(sayi1 int, sayi2 int): After the create function, we enter the function name and the variable names given in parentheses and the data types of these variables.

returns integer: We write the data type that will be returned as a result of the function.

language plpgsql: We select the language to be used in the function.

declare: In this section, we enter the variable name and data type that we will use in the function.

begin-end: We write the necessary plpgsql commands for the operations to be performed between the begin-end block.

Let’s write a function that converts the values entered in uppercase letters to lowercase letters and the letters containing “ı,ş,ç,ö,ğ,ü” into “i,ş,ö,g,u” respectively.

Loading

About Faruk Erdem

Leave a Reply

Your email address will not be published. Required fields are marked *