Given the following data set example, how should I structure my SQL query in order to determine if the value has grown over time (given a time range in the query) for a specific UserId by returning either a positive/negative growth percentage result or a true/false result UserId timestamp value 1 1617711825 3…
Tag: sql
PostgreSQL: deadlock without a transaction
I have a route (in a node JS app) that inserts and updates some data in a PostgreSQL database (version 13). In pseudo-code, here are all queries that are done in sequential order: On some instances of the app without that much traffic that writes on their own table, I have many deadlocks. I don’t unders…
Jooq insert one2one and one2many relational data into 2 tables at once. How to deal with issues and rollback
F.e. model How to insert it at once in jooq? How to deal with rollback if some query will fail? Is it has to be programated on my side? I can not find a word about such case in documentation 🙁 Should Id do it manually like: find author id in db by name if author not exist insert new
Divide by zero error encountered error. Null value is eliminated by an aggregate or other SET operation
In this specific part of a SP I’m trying to create, I’m getting an error: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Divide by zero error encountered. Additional error <2>: ErrorMsg: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Warning: Null value is eliminated by an aggr…
Combining Values in a Column by Date
I have been tasked with writing this simple query and am not sure where to go from here. I am trying to create a report that shows 3 columns: Date_Column, Id_Column, & Amount_Col. The table for Id_Column has different IDs based on a location column (in the table, but not in my query below). For the report…
Assuming there is enough disc space, can I create an index in a live production database without risk of downtime?
In a PostgreSQL database, assuming there is enough disc space, can I create an index in a live production database without risk of downtime? In other words, are there locks or possible crash or data loss possible or something else with the creation of an index. To be more precise, it’s an index on a JSO…
MySQL – why limit varchar
In MySQL you have to set a limit if you are to use a varchar. Does this limit only exist to make it less likely for devs to accidentally store too much data or is there any other reason (i.e. more effcient access) to set it to a low value? Answer VARCHAR columns are represented in the database with a
Java sql error when trying to update database
I am having a sql syntax issue when I am trying to update my databse through my update method which is trigured by a button here is the button code The update method code And the error Answer You missed the commas in the UPDATE statement. It should look like:
How to get around this error related to a CASE statement in my ORDER BY syntax?
I am using SQL Server 2014 and I am querying a linked server. My T-SQL query stands as follows: My issue is that I am getting the following error message when running the above T_SQL query: How can I get around this error? Answer I don’t know where the nested case expressions are coming from. But an alt…
Flatten the Data in BigQuery
I have dimensions.key_value of RECORD type i run the following query with following output. To unnest the data i have created the following view: My Output: There are two thing i need to verify is my query correct ? How i can make the query generic i.e if i don’t know all the key, there some other keys …