Quantcast
Channel: Active questions tagged cte - Database Administrators Stack Exchange
Browsing all 207 articles
Browse latest View live
↧

--- Article Not Found! ---

*** *** *** RSSing Note: Article is missing! We don't know where we put it!!. *** ***

View Article


Image may be NSFW.
Clik here to view.

How to show all the columns data in full outer join

I have 2 tables.The Result isIssue is EnteredBy=23 is not displaying because I am using CT1.EnteredBy.How to display CT11.EnteredBy value instead of NULLThe Actual Query I am using is given belowWith...

View Article


Why does a Postgres recursive CTE need the list of columns as argument?

This is kind of a subjective question.If I have a recursive CTE something like:WITH RECURSIVE r(x, y) AS ( ... SELECT x, y -- select1 FROM t WHERE .. UNION SELECT t.x, t.y -- select2 FROM r JOIN t ON...

View Article

best practice for dependency roots

When a database has a dependency table showing the parent-child relationship of items...I've mostly seen guides that assume the top level parent has a "parent id" field which is either zero or null,...

View Article

CTE Error when installing sp_WhoIsActive

I have several identical (near as I can tell) SQL Servers where I've recently added sp_WhoIsActive (showing some folks how much I like this tool) but one of them will not let me create the stored...

View Article


How to find child and grandchildren tables of a main table by order

I have this script to return all child and grandchildren tables with their level from a database . How do I change this if I only want to return the child and grandchildren tables of a particular table...

View Article

ON CONFLICT DO UPDATE command cannot affect row a second time when trying to...

Based on the SO: https://dba.stackexchange.com/a/46477 answer provided, I have been extending the Function with UPSERT in Postgres 9.5 or later for my own purposes to insert data into multiple...

View Article

What Rules Determine When SQL Server Use a CTE as an "Optimization Fence"?

A while back, Brent Ozar published a post detailing some of the differences between the SQL Server and PostgreSQL: Two Important Differences Between SQL Server and PostgreSQLThe first point (“CTEs are...

View Article


Do I need an explicit FOR UPDATE lock in a CTE in UPDATE?

In Postgres 13, I have a table which gets updated frequently. However, the update query is rather complicated and uses the same values multiple times. So, using a CTE seems quite a logical thing to...

View Article


Image may be NSFW.
Clik here to view.

How does SQL Server know not to execute Anchor element in Recursion CTE for...

I've been reading up on the inner workings of CTE Recursion and I'm still not quite sure how SQL Server is implementing the Anchor element in their source code and how SQL Server Query Execution Engine...

View Article

Recursive CTE get

I have the following tables:Table1identity_idvalueTable2 - Same structure as Table1identity_idvalueTable3source_iddestination_identity_idTable1 and Table2 are both partitions from the same table and...

View Article

Optimize Recursive CTE

I have the following query:WITH RECURSIVE node_path AS ( SELECT t1.record_id AS root_node, t2.destination_record_id AS end_node, ARRAY[t1.record_id, t2.destination_record_id] AS path_array FROM...

View Article

Image may be NSFW.
Clik here to view.

Generate dynamic number of columns from CTE

A hospital database (SQL Server 2016) has a table of visits to the hospital. If patients transfer to a different specialty, a new visit is made (but from a research perspective it's considered one...

View Article


CTE with UNION ALL not working as expected

The query below seems simple and straightforward, yet it produces unexpected results.CREATE TABLE #NUMBERS( N BIGINT);INSERT INTO #NUMBERS VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9);WITHA AS( -- CHOOSE...

View Article

Make this recursive CTE more dynamic

I have this script that enables me to extract hierarchies and the description for each level however the number of levels has to be known beforehand to define the number of select queries necessary for...

View Article


Return value from WITH clause in PL/pgSQL

I am attempting to RETURN an integer from a plpgsql MERGE-related action that uses WITH. The value I want to RETURN is within the WITH statement below - the id. The error I receive with the below code...

View Article

Insert values and add values to foreign key

I have two tables:CREATE TABLE est ( est_id serial PRIMARY KEY, est_nom varchar(70));CREATE TABLE bm ( id serial PRIMARY KEY, est_nom int, nom varchar(70), CONSTRAINT FK_bm_est FOREIGN KEY(est_nom)...

View Article


Is it possible to update an existing table in a single statement, using the...

I know I can achieve this in many ways - this is a purely academic question to see if it's possible to do this in a single statement, in order to further my knowledge of SQL.We're splitting an old,...

View Article

Unexpected behavior of a Postgres query with a JSONB column update inside a CTE

WITH deleted_files AS (SELECT name FROM files WHERE id = $1), updated_links AS ( UPDATE links l SET object = JSONB_SET(object, '{files}', (SELECT jsonb_agg(elem) FROM files nested,...

View Article

How to write query to link complex Parent-Child relationships

I used to think I was good at SQL until I received this latest request at work.We have a table that has a DefectID field, and a PreviousDefectID field, in order to link defect records to each other as...

View Article
Browsing all 207 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>