October 22, 2024
Chicago 12, Melborne City, USA

SQL

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample dat

SQL

compound indexing on databases

I am exploring the how indexes work under the hood. After going through some resources what I understood was ordering of indexes do matter in sql databases. But, I am confused of Nosql databases(Mongodb) After going through some resources, they mention it doesn’t matter. But I am confused how and why it doesn’t matter. Kindly

Read More
SQL

Denormalize to avoid many to many join table

Im working on a project which has these two tables: leagues and teams Each league can have many teams and a team can compete in many leagues. Initially, I was going to create a join table league-teams; however, I don’t find it necessary to create a new join table. We are talking about 1500 football

Read More
SQL

MsAccess SQL updating tables

I have an old tool that I’m trying to update to a new data source. Everything on the tool seems to be working other than when I try to update specific records based on a load number. Now, this column changed from a NUMBER format, to now a STRING format. That is the only difference.

Read More
SQL

Migrate ibatis choose cases to native SQL

I have the following ibatis query which I want to migrate from Oracle to PostgreSQL with Hibernate. BEGIN INSERT INTO users( user_id, personal_id, created_by, modified_by ) VALUES ( #{user_id}, #{personal_id}, <choose> <when test="userCred == true">'profile'</when> <otherwise>'basic'</otherwise> </choose>, <choose> <when test="userCred == true">'profile'</when> <otherwise>'basic'</otherwise> </choose> ); EXCEPTION WHEN HIST_INDEX THEN UPDATE .......... END; void insert(@Param("user_id") long

Read More
SQL

SQL, select by having duplicates in one column, but exclude if also 1:1 duplicate in other column

I need to select values from one column, that have duplicates, but exclude values, that also have duplicates in other column. Working with SQLite. Need query to be reasonably optimal. Example table: file checksum 2 1 3 1 4 2 4 2 5 3 5 3 6 3 SQL: CREATE TABLE t1 ( file INT,

Read More
SQL

Inconsistent Order of Results with COLLECT_SET Between Two Databricks Clusters old and new

I’m using Databricks with two different clusters (one from older version and one from new) to run a query that aggregates names, emails, and phone numbers from two data sources using COLLECT_SET. The goal is to combine these values into a single result per location. However, while the actual data is the same, the order

Read More
SQL

PostgreSQL zero-or-one to zero-or-one relationship

As the title describes I want to have a zero-or-one to zero-or-one relationship. For example, let’s say we have two tables Calls and Files. A call might have an attached file on it, and vice versa. But I have a restriction. I want if I delete a call, its file be deleted too, but if

Read More
SQL

SQL script called from Jenkins Pipeline does not output error or correct exit code

I am trying to run a SQL script from within a shell script to be used in a Jenkins pipeline in order to automate updates to my database schema. I am mostly trying to run ALTER TABLE commands that are saved in SQL files in a Git repository. The shell script searches all .sql files

Read More
SQL

Get the running minimum for 5 rows before on sampled data using QuestDB

I have a QuestDB table in which I get a few records every second. I am aggregating in 1 minute intervals, as in select timestamp, symbol, avg(price) as price from trades where timestamp in yesterday() and side="buy" sample by 1m Now I would like to get, for every sampled row, which was the minimum value

Read More
SQL

How Stored Procedures in SQL Called?

I now how to create the procedure but do not know how to call the procedure this is what I have done. Created the procedure : CREATE PROCEDURE SelectAllCustomers AS SELECT * FROM Customers GO; I have created it but next thing how to call the procedure, directly in the SQL console? You need to

Read More