Página traducida
Esta página se tradujo del inglés con ayuda de IA. Si hay diferencias entre ambas, la versión en inglés es la referencia.
CREATE VIEW
Crea una view o una materialized view dentro de una sesión, que se puede usar para representar una consulta stackql larga o compleja.
Consulte también:
[ SELECT ] [ REFRESH ] [ DROP ]
Sintaxis
createViewStatement::=
CREATE [ OR REPLACE ] [ MATERIALIZED ] VIEW <viewName> AS
<selectStatement> [ UNION | JOIN <selectStatement> ];
Ejemplos
UNION entre nubes con aws y google
CREATE VIEW dual_cloud_block_storage AS
SELECT
'google' AS vendor,
name,
split_part(split_part(type, '/', 11), '-', 2) AS type,
status,
sizeGb AS size
FROM google.compute.disks
WHERE project = '<YOUR_GCP_PROJECT>'
AND zone = 'australia-southeast1-a'
UNION
SELECT
'aws' AS vendor,
volumeId AS name,
volumeType AS type,
status,
size
FROM aws.ec2.volumes
WHERE region = 'ap-southeast-2';
Crear y usar una vista materializada
/* -------------------------- */
/* create a materialized view */
/* -------------------------- */
CREATE MATERIALIZED VIEW vw_ec2_instance_types AS
SELECT
memoryInfo,
hypervisor,
autoRecoverySupported,
instanceType,
SPLIT_PART(processorInfo, '\n', 3) as processorArch,
currentGeneration,
freeTierEligible,
hibernationSupported,
SPLIT_PART(vCpuInfo, '\n', 2) as vCPUs,
bareMetal,
burstablePerformanceSupported,
dedicatedHostsSupported
FROM aws.ec2.instance_types
WHERE region = 'us-east-1';
/* ------------------------- */
/* use the materialized view */
/* ------------------------- */
SELECT
i.instanceId,
i.instanceType,
it.vCPUs,
it.memoryInfo
FROM aws.ec2.instances i
INNER JOIN vw_ec2_instance_types it
ON i.instanceType = it.instanceType
WHERE i.region = 'us-east-1';