-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: common table expressions #7029
Comments
Already on the roadmap, though not currently on any near horizon. |
Linked into roadmap. |
This would be great to see. We're group number two on the internet who think they'd be handy to have 😄 An example of our use case for it: WITH p AS (
INSERT INTO user_edge (source_id, destination_id, position, updated_at)
SELECT ($1, $2, $3, $3)
WHERE EXISTS (SELECT id FROM users WHERE id=$1)
)
INSERT INTO user_edge_metadata (source_id, count, state, updated_at)
SELECT $1, 1, $2, $3 FROM p
ON CONFLICT(source_id) DO
UPDATE SET count = count + 1, updated_at = $3; The purpose of the query is to increment a counter field in a metadata table for every relation added to the |
@novabyte You might be able to achieve a similar effect using CTEs are definitely on our radar. |
Also note that the |
@tamird in this particular case the subquery is not correlated: |
This is needed to support ActiveRecord, which issues the following query:
|
To achieve this the recursion that instantiates the plans (currently |
Common Table Expressions (CTE) are also known as
WITH
clauses. They're currently unsupported, but came up in a recent tech talk we gave, and apparently at least one person on the internet thinks they're really useful.http://www.craigkerstiens.com/2013/11/18/best-postgres-feature-youre-not-using/
The text was updated successfully, but these errors were encountered: