{"id":1493,"date":"2025-01-06T11:59:53","date_gmt":"2025-01-06T04:59:53","guid":{"rendered":"https:\/\/www.pgtutorial.com\/?page_id=1493"},"modified":"2025-01-07T08:45:04","modified_gmt":"2025-01-07T01:45:04","slug":"plpgsql-if","status":"publish","type":"page","link":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/","title":{"rendered":"PL\/pgSQL IF"},"content":{"rendered":"\n<p><strong>Summary:<\/strong> In this tutorial, you&#8217;ll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.<\/p>\n\n\n\n<p>To execute one or more statements based on Boolean conditions, you use the <code>IF<\/code> statement.<\/p>\n\n\n\n<p>PL\/pgSQL offers three forms of the <code>IF<\/code> statements:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>IF-THEN<\/code><\/li>\n\n\n\n<li><code>IF-THEN-ELSE<\/code><\/li>\n\n\n\n<li><code>IF-THEN-ELSEIF<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='if-then-statement'>IF-THEN statement <a href=\"#if-then-statement\" class=\"anchor\" id=\"if-then-statement\" title=\"Anchor for IF-THEN statement\">#<\/a><\/h2>\n\n\n\n<p>Here&#8217;s the basic syntax of the <code>IF-THEN<\/code> statement:<\/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\"><span class=\"hljs-keyword\">IF<\/span> condition <span class=\"hljs-keyword\">THEN<\/span>\n    statement1;\n    statement2;\n<span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;<\/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>The <code>IF-THEN<\/code> statement evaluates a Boolean <code>condition<\/code>. If the condition evaluates to <code>true<\/code>, it executes one or more <code>statements<\/code> between the <code>THEN<\/code> and <code>END IF<\/code> keywords. Otherwise, it passes the control to the following statement after the <code>END IF<\/code>.<\/p>\n\n\n\n<p>The Boolean <code>condition<\/code> may include operators such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Comparison operators (<code>=<\/code>, <code>&lt;&gt;<\/code>, <code>&gt;<\/code>, <code>&gt;=<\/code>, <code>&lt;<\/code>, <code>&lt;=<\/code>) <\/li>\n\n\n\n<li>Logical operators like <code>AND<\/code>, <code>OR<\/code>, and <code>NOT<\/code>. <\/li>\n\n\n\n<li>The <code>IS NULL<\/code> and <code>IS NOT NULL<\/code> operators  If the condition involves <code><a href=\"https:\/\/www.pgtutorial.com\/postgresql-tutorial\/postgresql-not-null\/\">NULL<\/a><\/code>. <\/li>\n<\/ul>\n\n\n\n<p>The following example defines a function that uses the <code>IF-THEN<\/code> statement to display a notice when the product with an id is not found:<\/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\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">FUNCTION<\/span> get_price(id <span class=\"hljs-type\">INT<\/span>) <span class=\"hljs-keyword\">RETURNS<\/span> <span class=\"hljs-type\">DEC<\/span>\n<span class=\"hljs-keyword\">AS<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span>\n    v_price products.price<span class=\"hljs-meta\">%TYPE<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-keyword\">SELECT<\/span> price\n    <span class=\"hljs-keyword\">INTO<\/span> v_price\n    <span class=\"hljs-keyword\">FROM<\/span> products\n    <span class=\"hljs-keyword\">WHERE<\/span> product_id = id;\n\n    <span class=\"hljs-keyword\">IF<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-built_in\">FOUND<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'The product with id % was not found'<\/span>, id;\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n\n    <span class=\"hljs-keyword\">RETURN<\/span> v_price;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>\n<span class=\"hljs-keyword\">LANGUAGE<\/span> PLPGSQL;<\/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><a href=\"https:\/\/pgtutorial.com\/playground\/?q=Q1JFQVRFIEZVTkNUSU9OIGdldF9wcmljZShpZCBJTlQpIFJFVFVSTlMgREVDCkFTCiQkCkRFQ0xBUkUKICAgIHZfcHJpY2UgcHJvZHVjdHMucHJpY2UlVFlQRTsKQkVHSU4KICAgIFNFTEVDVCBwcmljZQogICAgSU5UTyB2X3ByaWNlCiAgICBGUk9NIHByb2R1Y3RzCiAgICBXSEVSRSBwcm9kdWN0X2lkID0gaWQ7CgogICAgSUYgTk9UIEZPVU5EIFRIRU4KICAgICAgUkFJU0UgTk9USUNFICdUaGUgcHJvZHVjdCB3aXRoIGlkICUgd2FzIG5vdCBmb3VuZCcsIGlkOwogICAgRU5EIElGOwoKICAgIFJFVFVSTiB2X3ByaWNlOwpFTkQ7CiQkCkxBTkdVQUdFIFBMUEdTUUw7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>How it works:<\/p>\n\n\n\n<p>First, retrieve the price of the product from the <code>products<\/code> table and assign it to the <code>v_price<\/code> variable using the <code>SELECT INTO<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT price\nINTO v_price\nFROM products\nWHERE product_id = id;<\/code><\/span><\/pre>\n\n\n<p>The <code>FOUND<\/code> is a special variable local to the block. The <code>SELECT INTO<\/code> statement sets the <code>FOUND<\/code> variable to <code>true<\/code> if there is a row returned or <code>false<\/code> otherwise.<\/p>\n\n\n\n<p>Second, check the <code>FOUND<\/code> variable and display a notice if the product with the id does not exist:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">IF NOT FOUND THEN\n   RAISE NOTICE <span class=\"hljs-string\">'The product with id % was not found'<\/span>, id;\nEND IF;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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<p>Third, return the product price:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">RETURN<\/span> v_price;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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>If you call the <code>get_price<\/code> function and pass a valid product id, you&#8217;ll get the product price:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT get_price(1);<\/code><\/span><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"> <span class=\"hljs-selector-tag\">get_price<\/span>\n<span class=\"hljs-selector-tag\">-----------<\/span>\n    999<span class=\"hljs-selector-class\">.99<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>However, if you use a product id that does not exist, you&#8217;ll get a notice:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT get_price(1000);<\/code><\/span><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">NOTICE:  The product <span class=\"hljs-keyword\">with<\/span> id <span class=\"hljs-number\">1000<\/span> was not found\n get_price\n-----------\n      NULL\n(<span class=\"hljs-number\">1<\/span> row)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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='if-then-else-statement'>IF-THEN-ELSE statement <a href=\"#if-then-else-statement\" class=\"anchor\" id=\"if-then-else-statement\" title=\"Anchor for IF-THEN-ELSE statement\">#<\/a><\/h2>\n\n\n\n<p>Here&#8217;s the syntax of the <code>IF-THEN-ELSE<\/code> statement:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" 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\">IF<\/span> condition <span class=\"hljs-keyword\">THEN<\/span>\n    statement1;\n<span class=\"hljs-keyword\">ELSE<\/span>\n    statement2;\n<span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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>If the <code>condition<\/code> is <code>true<\/code>, the <code>IF<\/code> statement executes the <code>statement1<\/code>. Otherwise, it executes the <code>statement2<\/code> in the <code>ELSE<\/code> clause. For example:<\/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\"><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">OR REPLACE<\/span> <span class=\"hljs-keyword\">FUNCTION<\/span> get_price(id <span class=\"hljs-type\">INT<\/span>) \n  <span class=\"hljs-keyword\">RETURNS<\/span> <span class=\"hljs-type\">DEC<\/span>\n<span class=\"hljs-keyword\">AS<\/span>\n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span>\n    v_price products.price<span class=\"hljs-meta\">%TYPE<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-keyword\">SELECT<\/span> price\n    <span class=\"hljs-keyword\">INTO<\/span> v_price\n    <span class=\"hljs-keyword\">FROM<\/span> products\n    <span class=\"hljs-keyword\">WHERE<\/span> product_id = id;\n\n    <span class=\"hljs-keyword\">IF<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-built_in\">FOUND<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n      <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'The product with id % was not found'<\/span>, id;\n    <span class=\"hljs-keyword\">ELSE<\/span> \n      <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'Price $%'<\/span>, v_price;\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n\n    <span class=\"hljs-keyword\">RETURN<\/span> v_price;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span>\n<span class=\"hljs-keyword\">LANGUAGE<\/span> PLPGSQL;<\/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><a href=\"https:\/\/pgtutorial.com\/playground\/?q=Q1JFQVRFIE9SIFJFUExBQ0UgRlVOQ1RJT04gZ2V0X3ByaWNlKGlkIElOVCkgUkVUVVJOUyBERUMKQVMKJCQKREVDTEFSRQogICAgdl9wcmljZSBwcm9kdWN0cy5wcmljZSVUWVBFOwpCRUdJTgogICAgU0VMRUNUIHByaWNlCiAgICBJTlRPIHZfcHJpY2UKICAgIEZST00gcHJvZHVjdHMKICAgIFdIRVJFIHByb2R1Y3RfaWQgPSBpZDsKCiAgICBJRiBOT1QgRk9VTkQgVEhFTgogICAgICBSQUlTRSBOT1RJQ0UgJ1RoZSBwcm9kdWN0IHdpdGggaWQgJSB3YXMgbm90IGZvdW5kJywgaWQ7CiAgICBFTFNFIAogICAgICBSQUlTRSBOT1RJQ0UgJ1ByaWNlICQlJywgdl9wcmljZTsKICAgIEVORCBJRjsKCiAgICBSRVRVUk4gdl9wcmljZTsKRU5EOwokJApMQU5HVUFHRSBQTFBHU1FMOw%3D%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>In this example, we modify the <code>get_price<\/code> function to raise a notice when the product not found and display the price otherwise:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">IF<\/span> NOT FOUND THEN\n   RAISE NOTICE <span class=\"hljs-string\">'The product with id % was not found'<\/span>, id;\n<span class=\"hljs-keyword\">ELSE<\/span> \n   RAISE NOTICE <span class=\"hljs-string\">'Price $%'<\/span>, v_price;\nEND <span class=\"hljs-keyword\">IF<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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>If the product id is valid, you&#8217;ll get the price back with a message:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT get_price(1);<\/code><\/span><\/pre>\n\n\n<p><a href=\"https:\/\/pgtutorial.com\/playground\/?q=U0VMRUNUIGdldF9wcmljZSgxKTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">NOTICE:  Price $999.99\n get_price\n-----------\n    999.99\n(1 row)<\/code><\/span><\/pre>\n\n\n<p>If the product id does not exist, you&#8217;ll get the product with the id not found:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT get_price(1000);<\/code><\/span><\/pre>\n\n\n<p><a href=\"https:\/\/pgtutorial.com\/playground\/?q=U0VMRUNUIGdldF9wcmljZSgxMDAwKTs%3D\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">NOTICE:  The product <span class=\"hljs-keyword\">with<\/span> id <span class=\"hljs-number\">1000<\/span> was not found\n get_price\n-----------\n      NULL\n(<span class=\"hljs-number\">1<\/span> row)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><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='if-then-elseif-statement'>IF-THEN-ELSEIF statement <a href=\"#if-then-elseif-statement\" class=\"anchor\" id=\"if-then-elseif-statement\" title=\"Anchor for IF-THEN-ELSEIF statement\">#<\/a><\/h2>\n\n\n\n<p>So far, you&#8217;ve learned how to use the <code>IF-THEN<\/code> and <code>IF-THEN-ELSE<\/code> statements to evaluate a single condition.<\/p>\n\n\n\n<p>When you have multiple conditions to evaluate, you can use the <code>IF-THEN-ELSEIF<\/code> statement with the following syntax:<\/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\">IF<\/span> condition1 <span class=\"hljs-keyword\">THEN<\/span>\n    statement1;\nELSEIF condition2 <span class=\"hljs-keyword\">THEN<\/span>\n    statement2;\nELSEIF condition3 <span class=\"hljs-keyword\">THEN<\/span>\n    statement3;\n&#91;<span class=\"hljs-keyword\">ELSE<\/span>\n    else_statement;]\n<span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/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<p>The <code>IF-THEN-ELSEIF<\/code> evaluates conditions sequentially from top to bottom. If a condition is <code>true<\/code>, it stops evaluating the subsequent condition and executes the corresponding statement. If no condition is <code>true<\/code>, it executes the statements in the <code>ELSE<\/code> branch.<\/p>\n\n\n\n<p>The following example defines a function that uses the <code>IF-THEN-ELSEIF<\/code> statement to get the price segment of a product based on its price:<\/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\">CREATE<\/span> <span class=\"hljs-keyword\">OR REPLACE<\/span> <span class=\"hljs-keyword\">FUNCTION<\/span> get_price_segment (id <span class=\"hljs-type\">INT<\/span>) \n  <span class=\"hljs-keyword\">RETURNS<\/span> <span class=\"hljs-type\">VARCHAR<\/span> <span class=\"hljs-keyword\">AS<\/span> \n$$<span class=\"pgsql\">\n<span class=\"hljs-keyword\">DECLARE<\/span>\n    v_price products.price<span class=\"hljs-meta\">%TYPE<\/span>;\n    v_price_segment <span class=\"hljs-type\">VARCHAR<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n    <span class=\"hljs-keyword\">SELECT<\/span> price\n    <span class=\"hljs-keyword\">INTO<\/span> v_price\n    <span class=\"hljs-keyword\">FROM<\/span> products\n    <span class=\"hljs-keyword\">WHERE<\/span> product_id = id;\n\n    <span class=\"hljs-keyword\">IF<\/span> <span class=\"hljs-keyword\">NOT<\/span> <span class=\"hljs-built_in\">FOUND<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n       <span class=\"hljs-keyword\">RAISE<\/span> <span class=\"hljs-keyword\">NOTICE<\/span> <span class=\"hljs-string\">'The product with id % was not found'<\/span>, id;\n       <span class=\"hljs-keyword\">RETURN<\/span> <span class=\"hljs-keyword\">NULL<\/span>;\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n\n    <span class=\"hljs-keyword\">IF<\/span> v_price &lt; <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n        v_price_segment = <span class=\"hljs-string\">'Low End'<\/span>;\n    ELSEIF v_price &gt;= <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">AND<\/span> v_price &lt; <span class=\"hljs-number\">400<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n        v_price_segment = <span class=\"hljs-string\">'Mid Range'<\/span>;\n    <span class=\"hljs-keyword\">ELSE<\/span>\n        v_price_segment = <span class=\"hljs-string\">'High End'<\/span>;\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n\n    <span class=\"hljs-keyword\">RETURN<\/span> v_price_segment;\n<span class=\"hljs-keyword\">END<\/span>;\n$$<\/span> <span class=\"hljs-keyword\">LANGUAGE<\/span> plpgsql;<\/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><a href=\"https:\/\/pgtutorial.com\/playground\/?q=Q1JFQVRFIE9SIFJFUExBQ0UgRlVOQ1RJT04gZ2V0X3ByaWNlX3NlZ21lbnQgKGlkIElOVCkgCiAgUkVUVVJOUyBWQVJDSEFSIEFTIAokJApERUNMQVJFCiAgICB2X3ByaWNlIHByb2R1Y3RzLnByaWNlJVRZUEU7CiAgICB2X3ByaWNlX3NlZ21lbnQgVkFSQ0hBUjsKQkVHSU4KICAgIFNFTEVDVCBwcmljZQogICAgSU5UTyB2X3ByaWNlCiAgICBGUk9NIHByb2R1Y3RzCiAgICBXSEVSRSBwcm9kdWN0X2lkID0gaWQ7CgogICAgSUYgTk9UIEZPVU5EIFRIRU4KICAgICAgIFJBSVNFIE5PVElDRSAnVGhlIHByb2R1Y3Qgd2l0aCBpZCAlIHdhcyBub3QgZm91bmQnLCBpZDsKICAgICAgIFJFVFVSTiBOVUxMOwogICAgRU5EIElGOwoKICAgIElGIHZfcHJpY2UgPCAyMDAgVEhFTgogICAgICAgIHZfcHJpY2Vfc2VnbWVudCA9ICdMb3cgRW5kJzsKICAgIEVMU0VJRiB2X3ByaWNlID49IDIwMCBBTkQgdl9wcmljZSA8IDQwMCBUSEVOCiAgICAgICAgdl9wcmljZV9zZWdtZW50ID0gJ01pZCBSYW5nZSc7CiAgICBFTFNFCiAgICAgICAgdl9wcmljZV9zZWdtZW50ID0gJ0hpZ2ggRW5kJzsKICAgIEVORCBJRjsKCiAgICBSRVRVUk4gdl9wcmljZV9zZWdtZW50OwpFTkQ7CiQkIExBTkdVQUdFIHBscGdzcWw7\" target=\"_blank\" rel=\"noreferrer noopener\">Try it<\/a><\/p>\n\n\n\n<p>First, retrieve the price of the product with a specific id from the <code>products<\/code> table and assign it to the <code>v_price<\/code> variable:<\/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\">SELECT<\/span>\n  price \n<span class=\"hljs-keyword\">INTO<\/span> v_price\n<span class=\"hljs-keyword\">FROM<\/span>\n  products\n<span class=\"hljs-keyword\">WHERE<\/span>\n  product_id = id;<\/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>Second, raise a notice and return <code>NULL<\/code> if the product with the id was not found:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">IF<\/span> NOT FOUND THEN\n   RAISE NOTICE <span class=\"hljs-string\">'The product with id % was not found'<\/span>, id;\n   <span class=\"hljs-keyword\">RETURN<\/span> <span class=\"hljs-keyword\">NULL<\/span>;\nEND <span class=\"hljs-keyword\">IF<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><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>Third, set the price segment based on the product price using the <code>IF-THEN-ELSEIF<\/code> statement:<\/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\">IF<\/span> v_price &lt; <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n   v_price_segment = <span class=\"hljs-string\">'Low End'<\/span>;\nELSEIF v_price &gt;= <span class=\"hljs-number\">200<\/span> <span class=\"hljs-keyword\">AND<\/span> v_price &lt; <span class=\"hljs-number\">400<\/span> <span class=\"hljs-keyword\">THEN<\/span>\n   v_price_segment = <span class=\"hljs-string\">'Mid Range'<\/span>;\n<span class=\"hljs-keyword\">ELSE<\/span>\n   v_price_segment = <span class=\"hljs-string\">'High End'<\/span>;\n<span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/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>Finally, return the product&#8217;s price segment:<\/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\">RETURN<\/span> v_price_segment;<\/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>The following statement calls the get_price_segment function to get the price segment of the product id 1:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT get_price_segment(1);<\/code><\/span><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\"> get_price_segment\n-------------------\n High End<\/code><\/span><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='nested-if-statements'>Nested IF statements <a href=\"#nested-if-statements\" class=\"anchor\" id=\"nested-if-statements\" title=\"Anchor for Nested IF statements\">#<\/a><\/h2>\n\n\n\n<p>Note that the <code>IF<\/code> statements can be nested. It means that you can place <code>IF<\/code> statements within other <code>IF<\/code> statements:<\/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\">IF<\/span> condition <span class=\"hljs-keyword\">THEN<\/span>\n    statement1;\n    <span class=\"hljs-keyword\">IF<\/span> condition2 <span class=\"hljs-keyword\">THEN<\/span>\n        statement2;\n    <span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/span>;\n<span class=\"hljs-keyword\">END<\/span> <span class=\"hljs-keyword\">IF<\/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>Please notice that code can become difficult to read if you use multiple levels of nesting.<\/p>\n\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>Use the <code>IF-THEN<\/code> statement to execute statements when a condition is <code>true<\/code>.<\/li>\n\n\n\n<li>Use the <code>IF-THEN-ELSE<\/code> statement to run statements when a condition is <code>true<\/code> and other statements when the condition is <code>false<\/code>.<\/li>\n\n\n\n<li>Use the <code>IF-THEN-ELSEIF<\/code> statement to evaluate multiple conditions and execute statements when the corresponding condition is <code>true<\/code>.<\/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-if\"\n  height=\"700\"\n  width=\"600\"\n  class=\"iframe\"\n><\/iframe>\n\n\n\n<p><\/p>\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=\"1493\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/\"\n\t\t\t\tdata-post-title=\"PL\/pgSQL IF\"\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=\"1493\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/\"\n\t\t\t\tdata-post-title=\"PL\/pgSQL IF\"\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>In this tutorial, you&#8217;ll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1420,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1493","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 IF Statement<\/title>\n<meta name=\"description\" content=\"In this tutorial, you&#039;ll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.\" \/>\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-if\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PL\/pgSQL IF Statement\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you&#039;ll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/\" \/>\n<meta property=\"og:site_name\" content=\"PostgreSQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-07T01:45:04+00:00\" \/>\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-if\\\/\",\"url\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-if\\\/\",\"name\":\"PL\\\/pgSQL IF Statement\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/#website\"},\"datePublished\":\"2025-01-06T04:59:53+00:00\",\"dateModified\":\"2025-01-07T01:45:04+00:00\",\"description\":\"In this tutorial, you'll learn how to execute one or more statements based on a condition using the PL\\\/pgSQL IF statement.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-if\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-if\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pgtutorial.com\\\/plpgsql\\\/plpgsql-if\\\/#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 IF\"}]},{\"@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 IF Statement","description":"In this tutorial, you'll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.","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-if\/","og_locale":"en_US","og_type":"article","og_title":"PL\/pgSQL IF Statement","og_description":"In this tutorial, you'll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.","og_url":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/","og_site_name":"PostgreSQL Tutorial","article_modified_time":"2025-01-07T01:45:04+00:00","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-if\/","url":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/","name":"PL\/pgSQL IF Statement","isPartOf":{"@id":"https:\/\/www.pgtutorial.com\/#website"},"datePublished":"2025-01-06T04:59:53+00:00","dateModified":"2025-01-07T01:45:04+00:00","description":"In this tutorial, you'll learn how to execute one or more statements based on a condition using the PL\/pgSQL IF statement.","breadcrumb":{"@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pgtutorial.com\/plpgsql\/plpgsql-if\/#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 IF"}]},{"@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\/1493","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=1493"}],"version-history":[{"count":10,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1493\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/www.pgtutorial.com\/wp-json\/wp\/v2\/pages\/1493\/revisions\/1531"}],"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=1493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}