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 6794531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:13:59+00:00 2026-05-26T18:13:59+00:00

Is it possible to rewrite the following plpgsql function as a sql function? I’m

  • 0

Is it possible to rewrite the following plpgsql function as a sql function?
I’m using it to aggregate my data by most recent timestamp, but wish to deploy on heroku which doesn’t support plpgsql.
I could totally rewrite my original query that uses this function, but I’d like to keep the flexibility for being able to drop in other aggregate functions.

CREATE OR REPLACE FUNCTION recent_accum(anyelement, anyelement)
  RETURNS anyelement AS $$
     BEGIN
        IF $1.tstamp IS NULL and $2.tstamp IS NOT NULL
           THEN RETURN $2;
        ELSEIF $1.tstamp IS NOT NULL and $2.tstamp IS NULL
           THEN RETURN $1;
        ELSEIF $2.tstamp > $1.tstamp
           THEN RETURN $2;
        ELSE RETURN $1;
        END IF;
     END;
  $$ LANGUAGE plpgsql;
  • 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-26T18:14:00+00:00Added an answer on May 26, 2026 at 6:14 pm

    Does it work to rewrite the IF/ELSEIF chain using CASE?

    CASE
    WHEN $1.tstamp IS NULL AND $2.tstamp IS NOT NULL
         THEN $2
    -- ...
    ELSE $1
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to rewrite the following hibernate query using grails criteria builder? select
Is it possible to rewrite the following code, so that it would be ISO
Is it possible to rewrite the following a bit more concise that I don't
I'm using a couple of rewrite directives that always works before on apache2 but
Using LAMP , is it possible to write rewrite rules to redirect URLs like
I would like to rewrite the following code in one line, using LINQ. Is
I wonder if it's always possible to rewrite LEFT JOIN using old Oracle syntax
Possible Duplicate: Can a JavaScript function return itself? Consider the following javascript function: var
Hi all is it possible to rewrite query: select userid from User where userid
Is it possible to re-write (Apache Mod-Rewrite) a URL from this: http://www.example.com/view.php?t=h5k6 to this

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.