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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:06:55+00:00 2026-06-08T20:06:55+00:00

I have a table with approximately 2.1 million tuples. Which has latitude and longitude

  • 0

I have a table with approximately 2.1 million tuples. Which has latitude and longitude columns. I am trying to convert this into a geographic type (point with SRID).

The function(procedure) I have written, works fine when I limit the entries (say : SELECT id,longitude,latitude FROM list_of_location limit 50).

CREATE OR REPLACE FUNCTION convertlatlon() RETURNS VOID AS $$
DECLARE rec RECORD;
BEGIN
    FOR rec IN SELECT id,longitude,latitude FROM list_of_location
    LOOP
    UPDATE list_of_location SET location= concat('SRID=4326;POINT(',rec.longitude,' ',rec.latitude,')') WHERE id=rec.id;    
    END LOOP;
END;
$$ LANGUAGE 'plpgsql' ;

  • When I try to run it on the entire table, PostgreSQL seems to do nothing. Have waited for an hour and a half.
  • Consumes 99% of CPU on the core it is running.
  • Does not spring any other instance of PostgreSQL to utilize other cores(since the request is from a single user?).
  • Is this because of locks(row level)?
  • How to circumvent this?

P.S. I am pretty sure this will get closed as off topic. But, I have to look for answers.

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

    I don’t know what would cause it, but it sounds like there may be locks acquired in this operation. You can verify this easily though:

    SELECT * FROM pg_locks;
    

    will tell you what locks are currently taken. And

    SELECT * FROM pg_stat_activities WHERE waiting;
    

    will tell you, if there are locks, which transactions are sitting there idle waiting for a lock to be released. That should point you on the right direction.

    Does not spring any other instance of PostgreSQL to utilize other cores(since the request is from a single user?).

    This is how postgres works. A single session will spin off one backend. A single query does not do any sort multi-process or concurrent operation.

    How to circumvent this?

    Why are you looping? I think you can do this in one shot. Why not do:

    UPDATE list_of_location 
    SET location = ST_GeogFromText('POINT(' || longitude || ' ' || latitude || ')');
    

    (assuming that gives you the correct result)

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

Sidebar

Related Questions

I have a table which has approximately 140 columns. The data for this table
We have a MyISAM table with approximately 75 milion rows that has 5 columns:
I have a table which has approximately sixty tables, and other tables are added
I have a table that has multiple columns which store a text value. For
I'm trying to use Hibernate to retrieve approximately 100 million rows from a table.
I have an Access database table with approximately 4 million rows. What i want
I have a table with approximately 120k rows, which contains a field with a
I have a table using innodb. I know the table has roughly 89 million
I have large database table, approximately 5GB, now I wan to getCurrentSnapshot of Database
I have table in which I am inserting rows for employee but next time

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.