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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:50:07+00:00 2026-05-31T07:50:07+00:00

I’m trying to create a function to insert data into a table. The query

  • 0

I’m trying to create a function to insert data into a table. The query I’m using won’t be changing except for the schema names need to be variables. For instance, one of my schema names is bscu.members and then there’s 35 others which are very similar (wea.members, pcu.members.. etc etc..). I couldn’t find any help on how to create a function in Postgresql using variables.

this is what i came up with so far but it isn’t working

create or replace function attsummary(varchar)
 RETURNS void
 LANGUAGE plpgsql
AS $function$
 BEGIN
insert into dwh.attribution_summary
select
m.source,
m.name,
m.partner_id,
d.ucic,
b.acct_type_desc as acct_desc,
a.begin_mo_balance as opening_balance,
c.date,
h.campaignname,
g.description as banner_desc,
f.create_time::timestamp as time_served,
'd' as dep_or_loan,
'h' as home_or_nonhome  
   from
$1.fact_deposits a
join $1.dim_acct_type b on a.acct_type_id = b.acct_type_id
join $1.dim_date c on a.date_id = c.date_id
join $1.dim_members d on a.ucic = d.ucic
join ad_delivery.sgmt_adic e on d.adic::varchar = e.adic
join ad_delivery.sgmt_user_tracker f on e.cookie_id = f.id
join ad_delivery.ox_banners g on g.bannerid = f.banner_id
join ad_delivery.ox_campaigns h on h.campaignid = f.campaign_id
join ad_delivery.sgmt_kli_adic i on e.adic = i.adic
join dwh.sgmt_clients m on m.partner_id = i.sgmt_partner_id
   where
  i.kli=8616208
   and m.partner_id::integer != 909909

and then my select statement comes after.. I am using $1 for my variable where the schema name usually goes.

  • 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-05-31T07:50:09+00:00Added an answer on May 31, 2026 at 7:50 am

    It must be dynamically generated

    create or replace function attsummary
    (schema text)
    returns void as
    $body$
    begin
    execute format('
    insert into dwh.attribution_summary
    select
        m.source,
        m.name,
        m.partner_id,
        d.ucic,
        b.acct_type_desc as acct_desc,
        a.begin_mo_balance as opening_balance,
        c.date,
        h.campaignname,
        g.description as banner_desc,
        f.create_time::timestamp as time_served,
        ''d'' as dep_or_loan,
        ''h'' as home_or_nonhome  
    from
    %1$s.fact_deposits a
    join %1$s.dim_acct_type b on a.acct_type_id = b.acct_type_id
    join %1$s.dim_date c on a.date_id = c.date_id
    join %1$s.dim_members d on a.ucic = d.ucic
    join ad_delivery.sgmt_adic e on d.adic::varchar = e.adic
    join ad_delivery.sgmt_user_tracker f on e.cookie_id = f.id
    join ad_delivery.ox_banners g on g.bannerid = f.banner_id
    join ad_delivery.ox_campaigns h on h.campaignid = f.campaign_id
    join ad_delivery.sgmt_kli_adic i on e.adic = i.adic
    join dwh.sgmt_clients m on m.partner_id = i.sgmt_partner_id
    where
        i.kli=8616208
        and m.partner_id::integer != 909909
    ', $1);
    end;
    $body$
    language plpgsql volatile
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.