Table doesn't update.

0

I'm creating a table with this query:

CREATE TABLE test_1 AS
SELECT id, created_at, transaction_type, customer_id, amount, description FROM "db_1"."transactions"
WHERE (customer_id != xxxx AND customer_id != yyyy) AND transaction_type = 'type_4' AND description = 'Some Description'
UNION ALL
SELECT id, created_at, transaction_type, customer_id, amount, description FROM "db_1"."transactions"
WHERE customer_id = xxxx AND (transaction_type = 'type_1'
OR transaction_type = 'type_2' OR transaction_type = 'type_3')

The query gets me what I need correctly, except that it doesn't update itself. The issue could be because I'm building a secondary table from the main table, but since the main table comes directly from an S3 bucket, when the bucket is updated, the main table updates as well. But the secondary table doesn't.

So, what should I do differently? Make a reference to the S3 bucket instead of the tables? How would that look like?

Thanks in advance for any suggestions.

preguntada hace un año239 visualizaciones
1 Respuesta
0

CREATE TABLE AS does not update the underlying data. https://docs.aws.amazon.com/athena/latest/ug/create-table-as.html

Instead try CREATE VIEW and the VIEW would be updated as the underlying data in the TABLE is updated. https://docs.aws.amazon.com/athena/latest/ug/create-view.html

profile pictureAWS
respondido hace un año
  • Thank you ananthtm!

    For instance, to make my previous query work, I should replace "CREATE TABLE" with "CREATE OR REPLACE VIEW"?

  • yes, using "CREATE OR REPLACE VIEW" should address your question. Please upvote and/or accept answer so that it helps everyone in this forum

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas