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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:12:24+00:00 2026-06-17T06:12:24+00:00

I have a table called members CREATE TABLE netcen.mst_member ( mem_code character varying(8) NOT

  • 0

I have a table called members

CREATE TABLE netcen.mst_member
(
  mem_code character varying(8) NOT NULL,
  mem_name text NOT NULL,
  mem_cnt_code character varying(2) NOT NULL,
  mem_brn_code smallint NOT NULL, -- The branch where the member belongs
  mem_email character varying(128),
  mem_cell character varying(11),
  mem_address text,
  mem_typ_code smallint NOT NULL,
  CONSTRAINT mem_code PRIMARY KEY (mem_code ))

each member type has a different sequence for the member code. i.e for gold members their member codes will be

GLD0091, GLD0092,…

and platinum members codes will be

PLT00020, PLT00021,…

i would like to have the default value for the field mem_code as a dynamic value depending on the member type selected. how can i use a check constraint to implement that??
please help, am using Postgresql 9.1

i have created the following trigger function to construct the string but i still get an error when i insert into the members table as Randy said.

CREATE OR REPLACE FUNCTION netcen.generate_member_code()
  RETURNS trigger AS
$BODY$DECLARE 
tmp_suffix text :='';
tmp_prefix text :='';
tmp_typecode smallint ;
cur_setting refcursor;
BEGIN
OPEN cur_setting FOR
EXECUTE 'SELECT typ_suffix,typ_prefix,typ_code FROM mst_member_type WHERE type_code =' || NEW.mem_typ_code ;
FETCH cur_setting into tmp_suffix,tmp_prefix,tmp_typecode;
CLOSE cur_setting;
NEW.mem_code:=tmp_prefix || to_char(nextval('seq_members_'|| tmp_typecode), 'FM0000000') || tmp_suffix;
END$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION netcen.generate_member_code()
  OWNER TO mnoma;

where could i be going wrong?
i get the following error

ERROR:  relation "mst_member_type" does not exist
LINE 1: SELECT typ_suffix,typ_prefix,typ_code FROM mst_member_type W...
                                                   ^
QUERY:  SELECT typ_suffix,typ_prefix,typ_code FROM mst_member_type WHERE typ_code =1
CONTEXT:  PL/pgSQL function "generate_member_code" line 7 at OPEN
  • 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-17T06:12:26+00:00Added an answer on June 17, 2026 at 6:12 am

    i think this is a normalization problem.

    the codes you provide are derivable from other information – therefore really do not belong as independent columns.

    you could just store the type in one column, and the number in another – then on any query where needed append them together to make this combo-code.

    if you want to persist this denormalized solution, then you could make a trigger to construct the string on any insert or update.

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

Sidebar

Related Questions

So I have a table called members and another table called group.The leader of
I have a table called members. I am looking on advice how to improve
For now, i have a table called members, which contains stuff, which is splitted
Ok, let's suppose we have members table. There is a field called, let's say,
I have a very simple table called Member , which consists of the following:
I have table called stats . In am inserting yes or no in the
i have table called as Support, which have a field named Name and contains
I have table called Buttons. Buttons table i have column button_number . Table contain
I have table called posts in my DB. Each post has field called social_network
I have a table called 'MyTable' that looks like: ID | Item | Type

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.