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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:52:20+00:00 2026-06-15T21:52:20+00:00

I have an SQL function: — Function: insert_into_wgs() — DROP FUNCTION insert_into_wgs(); CREATE OR

  • 0

I have an SQL function:

-- Function: insert_into_wgs()

-- DROP FUNCTION insert_into_wgs();

CREATE OR REPLACE FUNCTION insert_into_wgs()
  RETURNS void AS
$BODY$
BEGIN
INSERT INTO parcels (num,vid,support_num,name_dispatcher,cadastr,the_geom,status_id)  
SELECT num,vid,support_num,name_dispatcher,cadastr,ST_TRANSFORM(the_geom,4326),status_id
FROM parcels_temp
WHERE num NOT IN (SELECT num FROM parcels)AND deleted='no';
end;
$BODY$
LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION insert_into_wgs() OWNER TO postgres;

You see that it works only for parcels, parcels_temp tables. How can I create function with parameters insert_into_wgs(table, table_temp);?

  • 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-15T21:52:21+00:00Added an answer on June 15, 2026 at 9:52 pm

    As mentioned in the comment, you have to use dynamic SQL if you want to parametrize identifiers. And use EXECUTE in plpgsql.

    In the base query better use NOT EXISTS instead of col NOT IN (<subquery>).

    Now, if only the table names change and the columns stay the same, this simple demo would do the job:

    CREATE OR REPLACE FUNCTION insert_into_tbl(_tbl text, _tbl_tmp text)
      RETURNS void AS
    $func$
    BEGIN
    
    EXECUTE format($x$
    INSERT INTO %I (...)  -- enter columns
    SELECT ...            -- enter columns
    FROM %I t
    WHERE NOT EXISTS (
        SELECT 1
        FROM   %1$I p     -- reuse first table name
        WHERE  p.num = t.num
        )
    AND   deleted = 'no'$x$, _tbl, _tbl_tmp);
    
    END
    $func$ LANGUAGE plpgsql;
    

    Check out format() in the manual.
    There are quite a few related answers on SO. Try this search.

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

Sidebar

Related Questions

I have an sql function (no idea about sql) CREATE OR REPLACE FUNCTION RATELIMIT_OWN.Get_Conns_By_Login_IP_CallerId
I have a sql function in oracle create or replace function testfunc..... Compile it
SQL Server 2005 I have an SQL Function (ftn_GetExampleTable) which returns a table with
I have a huge problem with the REPLACE SQL function in Microsoft SQL Server
I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] (
I have an SQL function which returns a list of Teams. I want to
I have a sql function that accepts keywords and returns a full text search
I have a sql function that does a simple sql select statement: CREATE OR
Question: I have an SQL function which returns a list of files now I
I have PL/SQL function that returns cursor that holds 28 columns and 8100 rows.

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.