Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Introducción a las vistas
Una vista es una tabla virtual definida por una consulta en SQL. Puedes usar vistas a fin de proporcionar un nombre fácil de reutilizar para una consulta compleja o un conjunto limitado de datos y, luego, autorizar el acceso de otros usuarios. Una vez que creas una vista, un usuario puede consultarla como lo haría en una tabla. Los resultados de la consulta solo contienen los datos de las tablas y los campos especificados en la consulta que define la vista.
La consulta que define la vista se ejecuta cada vez que se consulta la vista. Si realizas consultas frecuentes en una vista costosa en cuanto al procesamiento, deberías considerar crear una vista materializada.
Las vistas de BigQuery se usan comúnmente para lo siguiente:
Abstraer y almacenar el cálculo y la lógica de unión en un objeto común para simplificar el uso de consultas
Proporcionar acceso a la lógica de cálculo y un subconjunto de datos sin acceder a las tablas base
También puedes usar una vista como fuente de datos para una herramienta de visualización como Looker Studio.
Comparación con las vistas materializadas
Las vistas son virtuales y proporcionan una referencia reutilizable a un conjunto de datos, pero no almacenan datos físicamente. Las vistas materializadas se definen con SQL, como una vista normal, pero almacenan de forma física los datos que BigQuery usa para mejorar el rendimiento. Para obtener una comparación adicional, consulta Funciones de vistas materializadas.
Limitaciones de las vistas
Las vistas de BigQuery están sujetas a las siguientes limitaciones:
Las vistas son de solo lectura. Por ejemplo, no puedes ejecutar consultas que inserten, actualicen o borren datos.
El conjunto de datos que contiene la vista y el conjunto de datos que contiene las tablas a las que hace referencia la vista deben estar en la misma ubicación.
Una referencia dentro de una vista se debe calificar con un conjunto de datos. El conjunto de datos predeterminado no afecta el cuerpo de una vista.
No puedes usar el método TableDataList de la API de JSON para recuperar datos desde una vista. Para obtener más información, consulta Tabledata: list.
No puedes mezclar consultas de SQL y GoogleSQL heredado cuando se usan vistas.
Una consulta de GoogleSQL no puede hacer referencia a una vista definida mediante la sintaxis de SQL heredado.
Los esquemas de las tablas subyacentes se almacenan con la vista cuando esta se crea. Si se agregan, borran o cambian columnas después de crear la vista,
esta no se actualizará de forma automática y el esquema informado
seguirá siendo inexacto hasta que se cambie la definición de SQL de la vista o se vuelva a
crear la vista. A pesar de que el esquema informado puede ser inexacto, todas
las consultas enviadas producen resultados precisos.
No puedes actualizar de forma automática una vista de SQL heredado en la sintaxis de GoogleSQL. Para cambiar la consulta usada para definir una vista, puedes usar lo siguiente:
No puedes incluir una función temporal definida por el usuario ni una tabla temporal en la consulta de SQL que define una vista.
No puedes hacer referencia a una vista en una consulta de tabla comodín.
Ver cuotas
Para obtener más información sobre las cuotas y los límites que se aplican a las vistas, consulta la página sobre límites de vistas.
Las consultas de SQL que se usan para definir las vistas también están sujetas a las cuotas en trabajos de consulta.
Ver los precios
Las vistas de BigQuery son vistas lógicas, no vistas materializadas.
Dado que las vistas no están materializadas, la consulta que define la vista se ejecuta cada vez que se consulta. Las consultas se facturan según la cantidad total de datos en todos los campos de la tabla a los que se hace referencia de forma directa o indirecta en la consulta de nivel superior. Para obtener más información, consulta Precios de consulta.
Ver la seguridad
Para controlar el acceso a las vistas en BigQuery, consulta Vistas autorizadas.
¿Qué sigue?
Para obtener información sobre cómo crear vistas, consulta Crea vistas.
Para obtener información sobre cómo crear una vista autorizada, consulta Crea vistas autorizadas.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-03-18 (UTC)"],[[["\u003cp\u003eViews in BigQuery are virtual tables defined by SQL queries, providing a reusable name for complex queries or a specific subset of data.\u003c/p\u003e\n"],["\u003cp\u003eUnlike materialized views, regular views do not store data physically; instead, the defining query is executed each time the view is queried.\u003c/p\u003e\n"],["\u003cp\u003eViews are read-only and subject to limitations such as requiring datasets to be in the same location and not being compatible with legacy SQL when using GoogleSQL.\u003c/p\u003e\n"],["\u003cp\u003eViews are used for simplifying query logic, abstracting calculations, and providing access to specific data subsets without exposing underlying tables, and they are also usable as a data source for visualization tools like Looker Studio.\u003c/p\u003e\n"],["\u003cp\u003eQuerying views incurs costs based on the total data size of the underlying tables' fields referenced in the view's defining query, and security is managed via authorized views.\u003c/p\u003e\n"]]],[],null,["# Introduction to logical views\n=============================\n\nThis document provides an overview of BigQuery support for logical\nviews.\n\nOverview\n--------\n\nA view is a virtual table defined by a SQL query. The default type of view for\nBigQuery is a *logical view*.\nQuery results contain only the data from the tables and fields\nspecified in the query that defines the view.\n\nThe query that defines a view is run each time the view is queried.\n\n**Types of views**\n\nAlthough logical views are the default type of view, if you frequently query a large or\ncomputationally expensive view, then you should consider creating a\n[*materialized view*](/bigquery/docs/materialized-views-intro), which is a\nprecomputed view that periodically caches the results of a query for increased performance and\nefficiency.\n\nHowever, you can often improve performance of a logical view without the need to create a\nmaterialized view by querying only a subset of your data, or by\n[using other techniques.](/bigquery/docs/materialized-views-intro#comparison)\n\nYou can also create an [*authorized view*](/bigquery/docs/authorized-views) to\nshare a subset of data from a source dataset to a view in a secondary dataset. You can then share\nthis view to specific users and groups (principals) who can view the data you share and run\nqueries on it, but who can't access the source dataset directly.\n\nYou can create an authorized view for either a logical or materialized view. An authorized view\nfor a materialized view is called an *authorized materialized view*.\n\n**Use cases**\n\nCommon use cases for views include the following:\n\n\n- Provide an easily reusable name for a complex query or a limited set of data that you can then [authorize](/bigquery/docs/authorized-views) other users to access. After you create a view, a user can then [query](/bigquery/docs/running-queries) the view as they would a table.\n- Abstract and store calculation and join logic in a common object to simplify query use.\n- Provide access to a subset of data and calculation logic without providing access to the base tables.\n- Optimize queries with high computation cost and small dataset results for [several use cases](/bigquery/docs/materialized-views-intro#use_cases).\n\n\u003cbr /\u003e\n\nYou can also use views in other contexts:\n\n- As a data source for a visualization tool such as [Looker Studio](/looker/docs).\n- As a means of sharing data to subscribers of [BigQuery sharing (formerly Analytics Hub)](/bigquery/docs/analytics-hub-introduction).\n\nComparison to materialized views\n--------------------------------\n\nLogical views are virtual and provide a reusable reference to a set of data, but\ndon't physically store any data. Materialized views are defined using SQL,\nlike a logical view, but physically store the data which BigQuery\nuses to improve performance. For further comparison, see\n[materialized views features](/bigquery/docs/materialized-views-intro#comparison).\n\nLogical views limitations\n-------------------------\n\nBigQuery views are subject to the following limitations:\n\n- Views are read-only. For example, you can't run queries that insert, update, or delete data.\n- The dataset that contains your view and the dataset that contains the tables referenced by the view must be in the same [location](/bigquery/docs/locations).\n- A reference inside of a view must be qualified with a dataset. The default dataset doesn't affect a view body.\n- You cannot use the `TableDataList` JSON API method to retrieve data from a view. For more information, see [Tabledata: list](/bigquery/docs/reference/rest/v2/tabledata/list).\n- You cannot mix GoogleSQL and legacy SQL queries when using views. A GoogleSQL query cannot reference a view defined using legacy SQL syntax.\n- You cannot reference [query parameters](/bigquery/docs/parameterized-queries) in views.\n- The schemas of the underlying tables are stored with the view when the view is created. If columns are added, deleted, or modified after the view is created, the view isn't automatically updated and the reported schema will remain inaccurate until the view SQL definition is changed or the view is recreated. Even though the reported schema may be inaccurate, all submitted queries produce accurate results.\n- You cannot automatically update a legacy SQL view to GoogleSQL syntax. To modify the query used to define a view, you can use the following:\n - The [**Edit query**](/bigquery/docs/updating-views#update-sql) option in the Google Cloud console\n - The [`bq update --view`](/bigquery/docs/reference/bq-cli-reference#bq_update) command in the bq command-line tool\n - The [BigQuery Client libraries](/bigquery/docs/reference/libraries)\n - The [update](/bigquery/docs/reference/rest/v2/tables/update) or [patch](/bigquery/docs/reference/rest/v2/tables/patch) API methods.\n- You cannot include a temporary user-defined function or a temporary table in the SQL query that defines a view.\n- You cannot reference a view in a [wildcard table](/bigquery/docs/querying-wildcard-tables) query.\n\nLogical views quotas\n--------------------\n\nFor information on quotas and limits that apply to views, see\n[View limits](/bigquery/quotas#view_limits).\n\nSQL queries used to define views are also subject to the quotas on\n[query jobs](/bigquery/quotas#query_jobs).\n\nLogical views pricing\n---------------------\n\nBigQuery uses logical views by default, not\n[materialized views](/bigquery/docs/materialized-views-intro).\nBecause views are not materialized by default, the query that defines the view\nis run each time the view is queried. Queries are billed according to the total\namount of data in all table fields referenced directly or indirectly by the top-level\nquery.\n\n- For general query pricing, see [On-demand compute pricing](/bigquery/pricing#on_demand_pricing).\n- For pricing associated with materialized views, see [Materialized views pricing](/bigquery/docs/materialized-views-intro#materialized_views_pricing).\n\nLogical views security\n----------------------\n\nTo control access to views in BigQuery, see\n[Authorized views](/bigquery/docs/authorized-views).\n\nWhat's next\n-----------\n\n- For information on creating views, see [Creating views](/bigquery/docs/views).\n- For information on creating an authorized view, see [Creating authorized views](/bigquery/docs/authorized-views).\n- For information on getting view metadata, see [Getting information about views](/bigquery/docs/view-metadata).\n- For more information on managing views, see [Managing views](/bigquery/docs/managing-views)."]]