Skip to main content
2 votes
1 answer
47 views

Do explicit locks in postgresql CTEs lock every row even with a cursor?

Let's say I have a table CREATE TABLE mytable ( user_id bigint, someval text ) In my application, I want to lock and fetch every row for some given user_id e.g. 123 to do some additional ...
negimaster's user avatar
3 votes
2 answers
78 views

Cumulative Stock Query without the participation of an Initial Stock Table

I'm designing a stock management program, here I have an Incoming Table like below: id (integer) date (date) type (varchar) warehouse_id (tinyint) goods_id (integer) quantity (decimal) price (decimal)...
Benson's user avatar
  • 145
3 votes
1 answer
205 views

How to implement this SQL query with CTE in Exposed DSL?

I have a SQL query that uses a Common Table Expression (CTE) with window functions, and I need to implement it using Kotlin's Exposed DSL. Since Exposed doesn't have built-in CTE support, I'm looking ...
user avatar
2 votes
0 answers
41 views

Attempting to understand CTE behaviour in clickhouse with ReplacingMergeTrees and FINAL

We Have the following table in clickhouse: CREATE TABLE db.user ( `id` String, `name` String, `version` UInt64 DEFAULT 0, ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{uuid}/{shard}',...
Tirtharaj Sengupta's user avatar
0 votes
1 answer
78 views

Why OPENQUERY fails with multiple CTEs with a where clause in some cases but not others

I have a query that contains two CTEs, one based on a linked Oracle server (from a SQL Server) that fails. I can fix it by doing any of the following: add a select limit (e.g. TOP 1000) to the SELECT ...
Anya Hayes's user avatar
4 votes
5 answers
184 views

Query to find the product name which has a continuous increase in sales every year

Product table with columns - PRODUCT_ID PRODUCT_NAME PRODUCT_ID PRODUCT_NAME 100 NOKIA 200 IPHONE 300 SAMSUNG 400 OPPO Sales table with columns - SALE_ID PRODUCT_ID YEAR QUANTITY Price SALE_ID ...
Rohan Srivastwa's user avatar
2 votes
1 answer
75 views

Recursive SQL query to hierarchyId

I currently have the problem that I get performance problems when migrating a large amount of data, the more data is migrated. As I cannot query the assignments of children to the TeamIds directly via ...
Andreas's user avatar
  • 67
0 votes
0 answers
185 views

How do I programmatically build a WITH 'ALIAS' AS (SELECT ...) CTE in sqlglot?

I'm trying to build a Common Table Expression (CTE) like this using the sqlglot Python library: WITH A AS ( SELECT * FROM my_table ) SELECT * FROM A When I attempt to build this with the ...
Carlos Oswaldo Alfaro He Him's user avatar
0 votes
4 answers
132 views

Recursive CTE to insert an entry for every day

Consider the following: IF OBJECT_ID('tempdb..#TetstData') IS NOT NULL DROP TABLE #TetstData CREATE TABLE #TetstData ( Id INT NOT NULL, PurchaseDate DATE NOT NULL, DepreciationRate ...
monstertjie_za's user avatar
1 vote
1 answer
118 views

How to use a recursive CTE in a JOIN statement

I'm working on converting an old database and queries to recursive CTEs. In the current code, I'm storing hierarchical data as a dash separated list of 0 padded strings. So as an example, I may have ...
Rohit's user avatar
  • 3,220
4 votes
5 answers
132 views

Cannot update postgres table from cte, value goes missing

I have a Postgres Timescaledb table (mysolar) in which I collect energyvalues (time,energy) from my solarpanels. Sometimes, for whatever reason, I get a ‘zero-value’ reading. (see example table). I ...
Leo's user avatar
  • 61
0 votes
2 answers
138 views

SQL query returns `ERROR: syntax error at or near "union"`

I am a beginner in SQL. What is the syntax issue with the query shown here? I just needed the random rows to be present n number of times. with recursive cte1 as ( select 1 as idx, company_id, ...
Nidhi's user avatar
  • 21
3 votes
2 answers
149 views

Recursive query for nomenclature like table with parent contains sum of all cost from children

I have a table like this: COMPOSANT COMPOSE QTE PA COST LEVEL PARENT1 CHILD1 24 0 PARENT1 CHILD2 2 0 CHILD1 CHILD11 10 1 CHILD1 CHILD12 4 3 12 1 CHILD11 CHILD111 100 1 100 2 CHILD2 CHILD21 5 10 50 1 ...
yoyogi785's user avatar
1 vote
3 answers
98 views

SQL query to aggregate and count non-null values across multiple columns

I have the following database schema. It looks at shoppers and how many orders they have made from three websites in a network. ID Name Country website1_Orders website2_Orders website3_Orders 123 ...
DJR's user avatar
  • 11
1 vote
3 answers
122 views

Postgres CTE with insert and update of same row

I have a table with auto generated id like below : CREATE TABLE wf_policy ( id BIGSERIAL PRIMARY KEY, name TEXT NOT NULL, time BIGINT, ver BIGINT ...
voidMainReturn's user avatar

15 30 50 per page
1
2 3 4 5
289