Skip to content

Tables created in complex queries are not cleaned #50

@joshleaves

Description

@joshleaves

This is an example of a query we have, using PostGreSQL's WITH statement:

WITH updated_records AS (
  UPDATE records SET updated_at = NOW(), foo = 'bar'
  WHERE type = 'custom_type'
  RETURNING id
)
INSERT INTO record_histories (record_id, action)
SELECT
  id AS record_id,
  'set_to_bar' AS action
FROM updated_records

Breaking it down into one UPDATE records... and one INSERT INTO record_histories.. queries would solve the issue but we'd like to avoid this solution if possible and keep our current codebase as is.

For minimal break of codebase, possible solutions rely on modifying the matcher regexp to either remove the leading \A (but then every test query that includes INSERT INTO xxxxx will add xxxxx to the tables to clean) or adding support for WITH xxxxx AS (...) INSERT INTO...-style queries to the regexp (which sounds dauting enough).

What would be your thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions