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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:40:29+00:00 2026-06-14T14:40:29+00:00

What’s the purpose of the following postgresql stored procedure, it’s used when execute a

  • 0

What’s the purpose of the following postgresql stored procedure, it’s used when execute a query, thank you!

CREATE OR REPLACE FUNCTION extract_fp_query(int[]) RETURNS int[]
AS $$
    SELECT uniq(sort(subarray($1 - 627964279,
        greatest(0, least(icount($1 - 627964279) - 120, 80)), 120)));
$$ LANGUAGE 'SQL' IMMUTABLE STRICT;
  • 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-06-14T14:40:30+00:00Added an answer on June 14, 2026 at 2:40 pm

    This code relies heavily on functionality in the intarray extension. Once you know that you can work it out by breaking it down into steps.

    It looks to me like some kind of poor-man’s crypto or obfuscation routine, but you’ve failed to provide any information about its inputs so it’s hard to say more. Essentially it returns a sorted, de-duplicated subset of the passed array, deciding which subset to return based on the number of elements in the array. If I read it correctly it removes the value 627964279 from the array if it appears there, then returns 120 elements (before de-duplication) from an offset of 0 and 80 elements into the array depending on the number of elements in the array.

    Create a test database. I’ll call mine regress. Create it and install the intarray contrib module into it as a superuser:

    sudo -u postgres createdb -O myusername regress
    sudo -u postgres psql regress -c 'CREATE EXTENSION intarray;'
    

    Now running as myusername, whatever your unpriveleged user account is, break the code down into steps and try each step. Just like you would in C. It might help to format it into expressions:

    SELECT uniq(sort(
        subarray(
            $1 - 627964279,
            greatest(
                0, 
                least(
                    icount($1 - 627964279) - 120,
                    80
                )
            )
            , 120
        )
    ));
    

    then evaluate each sub-expression by hand with a known input, substituting results as you go and simplifying the expression while jotting down what it does. I can’t do it for you because you haven’t supplied a sample input, but, replacing ARRAY[42,5,9,24,1,627964279] with your input array you’d do something like:

    $ psql regress
    psql (9.2.1)
    Type "help" for help.
    
    regress=> SELECT ARRAY[42,5,9,24,1,627964279];
              array          
    -------------------------
     {42,5,9,24,1,627964279}
    (1 row)
    
    regress=> SELECT ARRAY[42,5,9,24,1,627964279] - 627964279;
       ?column?    
    ---------------
     {42,5,9,24,1}
    (1 row)
    
    regress=> SELECT icount(ARRAY[42,5,9,24,1,627964279] - 627964279);
     icount 
    --------
          5
    (1 row)
    
    regress=> SELECT least(icount(ARRAY[42,5,9,24,1,627964279] - 627964279),80);
     least 
    -------
         5
    (1 row)
    
    regress=> 
    regress=> SELECT greatest(least(icount(ARRAY[42,5,9,24,1,627964279] - 627964279),80),0);
     greatest 
    ----------
            5
    (1 row)
    

    Now, by substituting 5 for the expression greatest(...) into the subarray expression we get:

    SELECT subarray($1 - 627964279, 5, 120 )
    

    which is after the evaluation of the array item removal:

    regress=> SELECT subarray(ARRAY[42,5,9,24,1], 5, 120);
     subarray 
    ----------
     {1}
    (1 row)
    

    In this case the sort and uniq have no further effect.

    What’s it for? Who knows, as you haven’t provided an input array that might offer clues.

    See the intarray documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.