Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3358778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:47:35+00:00 2026-05-18T02:47:35+00:00

Could you tell my why the following isnt working in postgres sql?: See updated

  • 0

Could you tell my why the following isnt working in postgres sql?:

See updated code below

UPDATE:

I expect the query to return “0.30” as float.
This construct is only for testing purposes, i have some complex querys which depend on this conditional structure… BUt i dont know how to fix it..

Result is:

ERROR:  syntax error at or near "1"
LINE 4:     if 1=1 then

UPDATE:

This construction appears in a function… so I want to do following:

CREATE FUNCTION f_test(myvalue integer) RETURNS float AS $$
  BEGIN
    select (
      case (select '1')
      when '1' then
        if 1=1 then
          0.30::float
        else
          0.50::float
        end
      else
         1.00::float
      end
    );
  END;
$$ LANGUAGE plpgsql;

select f_test(1) as test;

Error message see above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:47:36+00:00Added an answer on May 18, 2026 at 2:47 am

    There is no IF expr THEN result ELSE result END syntax for normal SQL queries in Postgres. As there is neither an IF() function as in MySQL, you have to use CASE:

    select (
      case (select '1')
      when '1' then
        case when 1=1 then 0.30::float else 0.50::float end
      else
         1.00::float
      end
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you tell me how to translate the following SQL code to Linq To
The following code is thread-safe as far as I can tell, with the caveat
The following R code generates a snippet from data frame I am working with
I have the following input values and I was hoping someone could kindly tell
Could someone tell me what the units the SetTimeout(int) method in the ICriteria interface
Could someone tell me why the SSRS web service ReportService2005.asmx has a recursive parameter
Could someone tell me how the field Task Group is used in standard SharePoint
Could someone please tell me which objects types can be tested using Regular Expressions
Could some one tell me how to capture SOAP messages passed between the client
Could anyone can tell me where I can find full ASP.NET MVC beta documentation?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.