Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How to implement per-user views of database?

I have a postgresql table that contains widgets and their various attributes. Each widget belongs to a group of users, but each user in the group may want to archive/hide any given widget from their view. There can be hundreds of these widgets and some users only care about some subset of them, but that becomes a per-user preference.

I'm at a loss as to how to efficiently implement this. I could include an "inactive" column on the widget table with a list of users that have hidden each row, but that seems horribly inefficient. Flipping it around so I store hidden items in a user profile doesn't seem much better as that list could get arbitrarily large over time. Are there any best practices for this sort of problem?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You are looking for a junction table. Here is an outline:

create table widgets (
    widgetId serial primary key,
    . . . 
);

create table users (
    userId serial primary key,
    . . .
);

create table userWidgets (
    userWidgetId serial primary key,
    userId int not null references users(userId),
    widgetId int not null references widgets(widgetId),
    isVisible boolean
);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda