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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:23:59+00:00 2026-06-12T13:23:59+00:00

I have PostgreSQL 8.4 with 3 pairs of tables like this: CREATE TABLE filedata_temp

  • 0

I have PostgreSQL 8.4 with 3 pairs of tables like this:

CREATE TABLE filedata_temp
(
 num serial NOT NULL,
 id integer,
 mydata character(25),
 the_geom geometry,
 CONSTRAINT filedata_temp_pkey PRIMARY KEY (num)
)

CREATE TABLE filedata
(
 num serial NOT NULL,
 id integer,
 mydata character(25),
 the_geom geometry,
 CONSTRAINT filedata_pkey PRIMARY KEY (num)
)

And 3 functions like this:

-- Function: insert_into_wgs()

-- DROP FUNCTION insert_into_wgs();

CREATE OR REPLACE FUNCTION insert_into_wgs()
RETURNS void AS
$BODY$
BEGIN
INSERT INTO filedata (num,id,mydata,the_geom)  
SELECT num,id,mydata,ST_TRANSFORM(the_geom,4326)
FROM filedata_temp
WHERE id NOT IN (SELECT id FROM filedata);
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION insert_into_wgs() OWNER TO postgres;
);

So i have 3 simular functions for 3 pairs of tables. Its not good. So can i make a one function for all 3 pairs? How to make 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-12T13:24:01+00:00Added an answer on June 12, 2026 at 1:24 pm

    Yes, you can. Use the PL/PgSQL EXECUTE ... USING statement to dynamically construct the SQL string and execute it. This will be quite a bit slower though, as there’s the PL/PgSQL call overhead and the cost of replanning the statement every time.

    More importantly, you appear to be attempting to write an upsert / merge function. This function is wrong. For why, see depesz’s excellent-as-usual article on upsert/merge.

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

Sidebar

Related Questions

I have a table with this layout: CREATE TABLE Favorites ( FavoriteId uuid NOT
I have a postgresql table userDistributions like this : user_id, start_date, end_date, project_id, distribution
I have PostgreSQL table with several boolean columns, currently containing only true or null
I have a PostgreSQL table with the following schema - CREATE TABLE test (
I am not able to make one clean SELECT I have postgresql table with
I have postgresql (in perlu) function getTravelTime(integer, timestamp), which tries to select data for
I have one postgresql table where I store some stories from different sites. At
That title is presumably awfully worded. I have some PostgreSQL tables. There is a
(I am using PostgreSQL) I have a table which stores transactions to an account.
I have a postgresql (v8.4) table with login id and timestamps, and I want

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.