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

  • Home
  • SEARCH
  • 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 8980355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:04:03+00:00 2026-06-15T20:04:03+00:00

I have the following function on a postgres-database: CREATE OR REPLACE FUNCTION getNearestPoints(float[], float[],

  • 0

I have the following function on a postgres-database:

CREATE OR REPLACE FUNCTION getNearestPoints(float[], float[], float[], float[], int)       
                    RETURNS SETOF record AS $$                                                                      
                DECLARE                                                                                             
                    i INT;                                                                                          
                    ret RECORD;     
                BEGIN                                                                                               
                    FOR i IN 1..$5 LOOP                                                                             
                         FOR ret IN EXECUTE 'SELECT height, ST_Y(point), ST_X(point)  FROM heights                   
                         WHERE ST_Intersects(ST_MakeEnvelope(' || $1[i] || ','  || $2[i] || ',' || $3[i] || ',' || $4[i] || ', 4326), point)' LOOP 
                         RETURN NEXT ret;                                                                           
                         END LOOP;                                                                                  
                    END LOOP;                                                                                       
                    RETURN;                                                                                         
                END;                                                                                                
                $$ LANGUAGE plpgsql;  

I want to return default values to the record for each column (e.g. (-2000, -181, -181)), if the query returns no rows.

Coalesce with records doesn’t seem to be possible.

How can I manage to do this?

  • 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-15T20:04:04+00:00Added an answer on June 15, 2026 at 8:04 pm

    If nothing was found then before RETURN you can assign values to the variable ret:

    ...
    if not found then
        ret = row(-2000::integer, -181::integer, -181::integer);
        return next ret;
    end if;
    
    return;
    ...
    

    Make sure that types used with row – “::integer” are the same as those in:

    SELECT height, ST_Y(point), ST_X(point)  FROM heights
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following function in Postgres: CREATE OR REPLACE FUNCTION point_total(user_id integer, gametime
I have the following function: func fitrange(a, x, b int) int { if a
I have the following function in a PHP script, which returns and API call:
suppose we have following function: void someFunction(int * araye){ for (int i=0;i<5;i++) cout <<araye[i]<<'
So in my postgres DB I have the following custom type: create type my_pg_type
I'm trying to create a FUNCTION in my Postgres database from a Bash script.
Let's say I have following function: int foo (int a) { return something; }
Have following kernel function: private static String programSource = __kernel void sampleKernel(__global float *Y,
I have following function in one Activity public void AppExit() { Editor edit =
In my MVC application in Controller i have following function to add and focus

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.