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

553
Vistas
Postgres View, after alter table to change table name, View still queries it?

Using Postgres database. I have an existing table, and several existing Views that query that table. Call the table, 'contacts'.

I alter the table, changing the name to 'contacts_backup'. I then created a new table with the same name the older table used to have 'contacts'

Now it appears that if I query the existing views, the data is still retrieved from the renamed table, contacts_backup, and not the new table, 'contacts'.

Can this be? How can I update the Views to query the new table of the same name, and not the renamed contacts_backup?

My new table is actually a foreign table, but shouldn't the principle be the same? I was expecting the existing tables to query against the new table, not the old renamed one.

What is an efficient way to update the existing views to query from the new table?

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

0

This is because PostgreSQL does not store the view definition as an SQL string, but as a parsed query tree.

These parsed query trees don't contain the names of the referenced objects, but only their object identifier (oid), which does not change when you rename an object. The same is true for table columns. This all holds for foreign tables as well.

When you examine the view definition, for example with pg_get_viewdef, the parse tree is rendered as text, so you will see the changed names.

If you want to change the table that a view is referring to, the only solution is to either DROP the view and CREATE it again, or you can use CREATE OR REPLACE VIEW.

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