I am searching for an index to make the following quick: The query is a delete and reads: so it deletes all rows that do not match a few hundred criteria on t1 and t2. explain gives a sequential scan and rearranges the query: Can I create an index that will avoid that full scan? Thanks in advance! Answer Alth…
Tag: sql
How to iterate over PostgreSQL jsonb array of objects and modify elements?
Given jsonb array and PostgreSQL 12: Need to convert it to: Is it possible somehow to iterate over jsonb array and downcase only “type” values? I tried: but it separates data and type pairs into separateelements. Answer You need an intermediate level of nesting to rebuild the objects before you ag…
Selecting additional data/values to display as column in query or in form
I have an employee index, that I need to run queries on for each employee, and display that output along with the original employee. So say the employee index has an ID, batch, status, and multiple other columns. I have a table where I keep track of every time a column in the employee index changes. I want to…
Is it possible to create a prepared statement and reuse it later with Java under postgres?
I am trying to test a few things out with postgres. I want to know if it’s possible to create define a PreparedStatement such as String statement = “Insert into table_one values (?)”; …
Oracle Merge – Can I do something like “When Not Matched Then Delete”?
I have a table (t1) with a unique list of patients. I have another table (t1_Backup) with a duplicative list of patients and details. I would like to essentially perform an inner join to update t1, …
Postgres expand JSON with unkown keys
I want to expand a specific row in my table which has a json column with the followingstructure: id|column1 | —|————-| id1|{nested json}| id2|{nested json}| Structure of nested JSON …
Find the sum total of two CASE statements – (How to use a CASE expression or Lateral JOIN
I am looking to find the total profit made on an each way horse racing bet I have created a view to show odds and returns for each part of the bet, but I would like to add another column (EachWayProfit) to find the total profit. I have tried to simply SUM the two case statements though receiving a Syntax
2 dimensional table query with join and PostgreSQL [closed]
Trying to return a 2 dimensional table from SQL query (Postgres). Read about Pivot Table (but not sure if it is valid for join) and crosstab/tablefunc but no luck. Expected result App A | …
Does using EXISTS instruction improves this query
Im learning how to improve some queries I have, for example I saw that using EXISTS over IN does better, so I did the following modification but im not 100% sure if im getting the same results I …
Why this IF NOT EXISTS statement is not ok?
I’m trying to create a table but it keeps giving me error and I’m not able to figure out the problem even after checking the manual That’s the code: Answer I solved by using a different word from VALUE. It is already defined as keyword