{"id":1436,"date":"2025-01-04T20:43:16","date_gmt":"2025-01-04T13:43:16","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=1436"},"modified":"2025-01-12T10:07:09","modified_gmt":"2025-01-12T03:07:09","slug":"plpgsql-variables","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/","title":{"rendered":"PL\/pgSQL Variables"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you&#8217;ll learn about PL\/pgSQL variables and how to declare, assign, and use variables.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='overview-of-plpgsql-variables'>Overview of PL\/pgSQL Variables <a href=\"#overview-of-plpgsql-variables\" class=\"anchor\" id=\"overview-of-plpgsql-variables\" title=\"Anchor for Overview of PL\/pgSQL Variables\">#<\/a><\/h2>\n\n\n\n<p>In PL\/pgSQL, variables are identifiers with immediate values of various SQL types such as <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-integer\/\">integer<\/a>, <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-varchar\/\">varchar<\/a>, and <a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-boolean\/\">boolean<\/a>.<\/p>\n\n\n\n<p>Before using variables, you must declare them in the declaration section of the block.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='declaring-a-variable'>Declaring a Variable <a href=\"#declaring-a-variable\" class=\"anchor\" id=\"declaring-a-variable\" title=\"Anchor for Declaring a Variable\">#<\/a><\/h3>\n\n\n\n<p>Here&#8217;s the syntax for declaring a variable:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">variable_name data_type &#91;=initial_value];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, provide a variable nam <code>variable_name<\/code>.<\/li>\n\n\n\n<li>Second, specify the data type of value that the variable will hold. The <code>data_type<\/code> can be any SQL&#8217;s data type like <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-integer\/\">INT<\/a><\/code>, <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-decimal\/\">DECIMAL<\/a><\/code>, <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-varchar\/\">VARCHAR<\/a><\/code>, and <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-text\/\">TEXT<\/a><\/code>.<\/li>\n\n\n\n<li>Third, assign an optional initial value to the variable. The variable will use <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-not-null\/\">NULL<\/a><\/code> by default if you don&#8217;t assign an initial value.<\/li>\n<\/ul>\n\n\n\n<p>Besides the assignment operator, you can use the <code>:=<\/code> operator to assign an initial value to a variable:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">variable_name data_type &#91;:=initial_value];<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following declares a variable called <code>total_quantity<\/code> with the type <code>INT<\/code> and initial value <code>0<\/code> in the declaration section and displays its value in the body section:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DO<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">0<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n     <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">NOTICE<\/span>:  Total quantity <span class=\"hljs-number\">0<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Besides the <code>=<\/code> and <code>:=<\/code> operators, you can use the <code>DEFAULT<\/code> keyword to specify an initial value of a variable:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DECLARE<\/span> \n    variable_name data_type <span class=\"hljs-keyword\">DEFAULT<\/span> initial_value;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity INT <span class=\"hljs-keyword\">DEFAULT<\/span> <span class=\"hljs-number\">0<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>After initialization, you can use the variable in the later initialization within the same block. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DECLARE<\/span>\n    min_shipping_cost DEC = <span class=\"hljs-number\">5<\/span>;\n    net_price DEC = min_shipping_cost;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this declaration, the initial value of the <code>net_price<\/code> is the value of the <code>min_shipping_cost<\/code> variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='assigning-a-value-to-a-variable'>Assigning a Value to a Variable <a href=\"#assigning-a-value-to-a-variable\" class=\"anchor\" id=\"assigning-a-value-to-a-variable\" title=\"Anchor for Assigning a Value to a Variable\">#<\/a><\/h3>\n\n\n\n<p>To assign a value to a variable, you can use the assignment operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">variable_name = <span class=\"hljs-keyword\">value<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Or you can use the <code>:=<\/code> operator:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">variable_name := <span class=\"hljs-keyword\">value<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For example, the following shows how to assign <code>10<\/code> to the <code>total_quantity<\/code> variable:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DO<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">0<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n     total_quantity = <span class=\"hljs-number\">10<\/span>;\n     <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">NOTICE<\/span>:  Total quantity <span class=\"hljs-number\">10<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='variable-scopes'>Variable Scopes <a href=\"#variable-scopes\" class=\"anchor\" id=\"variable-scopes\" title=\"Anchor for Variable Scopes\">#<\/a><\/h2>\n\n\n\n<p>The scope of a variable specifies where in the code you can reference it.<\/p>\n\n\n\n<p>In PL\/pgSQL, the scope of a variable is within the block and nested blocks of the block where you declare it: <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"290\" src=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png\" alt=\"PL\/pgSQL variable scope\" class=\"wp-image-1442\" srcset=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png 400w, https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope-300x218.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/figure>\n\n\n\n<p>For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DO<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">0<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n     total_quantity = <span class=\"hljs-number\">10<\/span>;\n     <span class=\"hljs-keyword\">DECLARE<\/span>\n          safety_stock <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">10<\/span>;\n          on_hand_qty <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">200<\/span>;\n     <span class=\"hljs-keyword\">BEGIN<\/span>\n           total_quantity := safety_stock + on_hand_qty;\n     <span class=\"hljs-keyword\">END<\/span>;\n     <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, we declare a variable <code>total_quantity<\/code> in the outer block:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">0<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Therefore, we can access it in the nested block:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">total_quantity := safety_stock + on_hand_qty;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In the subblock, we declare two variables, <code>safety_stock<\/code> and <code>on_hand_qty<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DECLARE<\/span>\n    safety_stock <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">10<\/span>;\n    on_hand_qty <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">200<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>They can only be accessed within the subblock. If you attempt to access them from the outer block, you&#8217;ll get an error:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DO<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">0<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n     total_quantity = <span class=\"hljs-number\">10<\/span>;\n     <span class=\"hljs-keyword\">DECLARE<\/span>\n          safety_stock <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">10<\/span>;\n          on_hand_qty <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">200<\/span>;\n     <span class=\"hljs-keyword\">BEGIN<\/span>\n           total_quantity := safety_stock + on_hand_qty;\n     <span class=\"hljs-keyword\">END<\/span>;\n     <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity;\n     <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'safety_stock %, on-hand quantity %'<\/span>, safety_stock, on_hand_qty; <span class=\"hljs-comment\">-- error<\/span>\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>PL\/pgSQL allows different variables declared in the outer and subblock to share the same names. However, it is not a good practice to do so.<\/p>\n\n\n\n<p>If this is the case, the variable in the subblock will hide the variable in the outer block. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DO<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">10<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n     <span class=\"hljs-keyword\">DECLARE<\/span>\n          total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">20<\/span>;\n     <span class=\"hljs-keyword\">BEGIN<\/span>\n            <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity; <span class=\"hljs-comment\">-- 20<\/span>\n     <span class=\"hljs-keyword\">END<\/span>;\n     <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity; <span class=\"hljs-comment\">-- 10<\/span>\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">NOTICE<\/span>:  Total quantity <span class=\"hljs-number\">20<\/span>\n<span class=\"hljs-keyword\">NOTICE<\/span>:  Total quantity <span class=\"hljs-number\">10<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the nested block displays the value of the <code>total_quantity<\/code> declared in the nested block, and the outer block shows the value of the <code>total_quantity<\/code> declared in the outer block. In other words, the <code>total_quantity<\/code> variable in the nested block hides the <code>total_quantity<\/code> variable in the outer block.<\/p>\n\n\n\n<p>To access the <code>total_quantity<\/code> variable in the outer block within the nested block, you need to use the block label:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DO<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-symbol\">&lt;&lt;main&gt;&gt;<\/span>\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">10<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n     <span class=\"hljs-keyword\">DECLARE<\/span>\n          total_quantity <span class=\"hljs-type\">INT<\/span> = <span class=\"hljs-number\">20<\/span>;\n     <span class=\"hljs-keyword\">BEGIN<\/span>\n            <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity %'<\/span>, total_quantity;\n            <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Total quantity in the outer block %'<\/span>, main.total_quantity; \n     <span class=\"hljs-keyword\">END<\/span>;\n<span class=\"hljs-keyword\">END<\/span> main;\n$$<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-20\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">NOTICE<\/span>:  Total quantity <span class=\"hljs-number\">20<\/span>\n<span class=\"hljs-keyword\">NOTICE<\/span>:  Total quantity <span class=\"hljs-keyword\">in<\/span> the <span class=\"hljs-keyword\">outer<\/span> block <span class=\"hljs-number\">10<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-20\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='constants'>Constants <a href=\"#constants\" class=\"anchor\" id=\"constants\" title=\"Anchor for Constants\">#<\/a><\/h2>\n\n\n\n<p>Sometimes, you want to define variables whose values cannot be changed. To do that you can declare constants.<\/p>\n\n\n\n<p>Here&#8217;s the syntax for declaring a constant:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">constant_name CONSTANT data_type = initial_value;<\/code><\/span><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code>CONSTANT<\/code> keyword indicates that the value of the <code>constant_name<\/code> cannot be changed after initialization.<\/li>\n\n\n\n<li><code>initial_value<\/code> is the constant value.<\/li>\n<\/ul>\n\n\n\n<p>For example, in the following block, we declare a constant PI which is approximately <code>3.14<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-21\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">DO<\/span>\n$$\n<span class=\"hljs-keyword\">DECLARE<\/span> \n    pi CONSTANT DEC = <span class=\"hljs-number\">3.14<\/span>;\n    v_radius DEC = <span class=\"hljs-number\">10<\/span>;\n    v_area DEC;\nBEGIN\n    v_area = pi * v_radius * v_radius;\n    RAISE NOTICE <span class=\"hljs-string\">'The area of a circle with the radius % is %'<\/span>, v_radius, v_area;\nEND;\n$$;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-21\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The block calculates the area of a circle with a radius of 10.<\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-22\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">NOTICE:  The area <span class=\"hljs-keyword\">of<\/span> a circle <span class=\"hljs-keyword\">with<\/span> the radius <span class=\"hljs-number\">10<\/span> is <span class=\"hljs-number\">314.00<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-22\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A variable is an identifier that holds an immediate value of any SQL type.<\/li>\n\n\n\n<li>Declare variables in the block&#8217;s declaration section.<\/li>\n\n\n\n<li>Scopes of variables are blocks where they are declared. Nested blocks can access variables declared in the outer block.<\/li>\n\n\n\n<li>Constants are variables whose values cannot change after initialization.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='quiz'>Quiz <a href=\"#quiz\" class=\"anchor\" id=\"quiz\" title=\"Anchor for Quiz\">#<\/a><\/h2>\n\n\n\n<iframe loading=\"lazy\"\n  name=\"quiz\"\n  src=\"\/quiz\/?quiz=plpgsql-variables\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1436\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/\"\n\t\t\t\tdata-post-title=\"PL\/pgSQL Variables\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1436\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/\"\n\t\t\t\tdata-post-title=\"PL\/pgSQL Variables\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ll learn about PL\/pgSQL variables, and how to declare, assign, and use variables. You&#8217;ll also understand variable scopes in PL\/pgSQL.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1420,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1436","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PL\/pgSQL Variables<\/title>\n<meta name=\"description\" content=\"You&#039;ll learn about PL\/pgSQL variables, and how to declare, assign, and use variables. You&#039;ll also understand variable scopes in PL\/pgSQL.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PL\/pgSQL Variables\" \/>\n<meta property=\"og:description\" content=\"You&#039;ll learn about PL\/pgSQL variables, and how to declare, assign, and use variables. You&#039;ll also understand variable scopes in PL\/pgSQL.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-12T03:07:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png\" \/>\n\t<meta property=\"og:image:width\" content=\"400\" \/>\n\t<meta property=\"og:image:height\" content=\"290\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/\",\"name\":\"PL\\\/pgSQL Variables\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/plpgsql-variable-scope.png\",\"datePublished\":\"2025-01-04T13:43:16+00:00\",\"dateModified\":\"2025-01-12T03:07:09+00:00\",\"description\":\"You'll learn about PL\\\/pgSQL variables, and how to declare, assign, and use variables. You'll also understand variable scopes in PL\\\/pgSQL.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/plpgsql-variable-scope.png\",\"contentUrl\":\"https:\\\/\\\/www.pgtutorial.com\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/plpgsql-variable-scope.png\",\"width\":400,\"height\":290,\"caption\":\"PL\\\/pgSQL variable scope\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-variables\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PL\\\/pgSQL\",\"item\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PL\\\/pgSQL Variables\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/\",\"name\":\"PostgreSQL Tutorial\",\"description\":\"Learn PostgreSQL from Scratch\",\"alternateName\":\"PostgreSQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pgtutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PL\/pgSQL Variables","description":"You'll learn about PL\/pgSQL variables, and how to declare, assign, and use variables. You'll also understand variable scopes in PL\/pgSQL.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/","og_locale":"en_US","og_type":"article","og_title":"PL\/pgSQL Variables","og_description":"You'll learn about PL\/pgSQL variables, and how to declare, assign, and use variables. You'll also understand variable scopes in PL\/pgSQL.","og_url":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-01-12T03:07:09+00:00","og_image":[{"width":400,"height":290,"url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/","url":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/","name":"PL\/pgSQL Variables","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/#primaryimage"},"image":{"@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png","datePublished":"2025-01-04T13:43:16+00:00","dateModified":"2025-01-12T03:07:09+00:00","description":"You'll learn about PL\/pgSQL variables, and how to declare, assign, and use variables. You'll also understand variable scopes in PL\/pgSQL.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/#primaryimage","url":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png","contentUrl":"https:\/\/www.pgtutorial.com\/wp-content\/uploads\/2025\/01\/plpgsql-variable-scope.png","width":400,"height":290,"caption":"PL\/pgSQL variable scope"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-variables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pgtutorial.com\/"},{"@type":"ListItem","position":2,"name":"PL\/pgSQL","item":"https:\/\/www.pgtutorial.com\/plpgsql\/"},{"@type":"ListItem","position":3,"name":"PL\/pgSQL Variables"}]},{"@type":"WebSite","@id":"https:\/\/www.pgtutorial.com\/#website","url":"https:\/\/www.pgtutorial.com\/","name":"PostgreSQL Tutorial","description":"Learn PostgreSQL from Scratch","alternateName":"PostgreSQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pgtutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/comments?post=1436"}],"version-history":[{"count":11,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1436\/revisions"}],"predecessor-version":[{"id":1638,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1436\/revisions\/1638"}],"up":[{"embeddable":true,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1420"}],"wp:attachment":[{"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/media?parent=1436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}