0

Lets say I have a table with the following columns:

  • first_name
  • last_name
  • height
  • social_security_number
  • phone_number

Let's say I very often fetch first_name, last_name, and height together when I'm fetching public data, so I want to bundle them together

Similarly, I want to bundle social_security_number and phone_number as private data.

In order to simplify my queries and not make a mistake in the future, I want to create some sort of a multi-column reference that will serve as an alias to public and private data, so:

I want to do something like this:

(made up syntax)

ALTER TABLE acc CREATE BUNDLE first_name, last_name, height AS public_acc_columns;
ALTER TABLE acc CREATE BUNDLE social_security_number, phone_number AS private_acc_columns;

And then use it like this

 -- returns first_name, last_name, height
SELECT public_acc_columns FROM acc;

 -- returns social_security, phone_number
SELECT private_acc_columns FROM acc;

 -- returns all columns
SELECT public_acc_columns, private_acc_columns FROM acc;
1
  • 1
    what is bundle!!! you can make two view to achieve your goal Commented Jan 6, 2021 at 0:12

1 Answer 1

2

I would advise creating two SQL Views. Setup one as acc_public and one as acc_private. Although I don’t know that the private would be needed.

Then you could say:

Select * from acc_public

Or

Select * from acc_private

Without seeing all your data structure, I can’t say the syntax you would need for the view, but here is some general information: https://www.w3schools.com/sql/sql_view.asp

Sign up to request clarification or add additional context in comments.

2 Comments

Yep, this looks like the solution that best fits the "in six months, will I understand what I did?" criteria.
Simple and maintainable. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.