I am trying to write a query to print the maximum number of discounted tours any one family can choose from. For example, the Thomas family can choose from any of the 3 tours and qualify for the …
Quick way to find a word using a SQL query
My current code is to try to find 2 words “Red Table” in Title: The problem is, this is so slow! I even put the status “Index” to the column Title. I just want to search for multiple words in one (I would prefer in title AND description), but obviously I can’t use LIKE because it…
How do I find the maximum depending on multiple subranges within one column
I have two tables: Orders and Customers. Orders lists all bought items (policy_id) and Customers information such as their age. The two tables are linked via the customer_id. Now I want to find the …
How to compare the value of one row with the upper row in one column of an ordered table?
I have a table in PostgreSQL that contains the GPS points from cell phones. It has an integer column that stores epoch (the number of seconds from 1960). I want to order the table based on time (epoch column), then, break the trips to sub trips when there is no GPS record for more than 2 minutes. I did it
adding many to many relations is producing an empty queryset
I have a model called Occurrence with a number of foreign key and manytomany relationships (i’ve only shown a few fields here). I am having issues when attempting to create any manytomany relation to an Occurrence instance after I have loaded bulk data to my postgres (postgis) database using the sqlalch…
Compare two arrays in PostgreSQL
I have a table in postgres with a value column that contains string arrays. My objective is to find all arrays that contain any of the following strings: {‘cat’, ‘dog’} The following query uses ANY() to check if ‘dog’ is equal to any of the items in each array and will corr…
T-SQL filtering records based on dates and time difference with other records
I have a table for which I have to perform a rather complex filter: first a filter by date is applied, but then records from the previous and next days should be included if their time difference does …
Get rid of all empty strings values in jsonb | Postgres
I have rather abstract question on PostgreSQL jsonb data. For example I have a table called… table_one, where I have a column: In 100% cases in contains flat json structure like example: might be different length or null but always flat. My goal is like that. Whenever I select this column I need to somehow co…
query inside the exception and begin block in exception
Hello I want to ask what is the best practise to do. First example try to retrieve my data through exceptions I use this code in my main application and is working fine but I dont know if its good practise to code inside the exceptions blocks SECOND EXAMPLE TRY TO RETRIEVE DATA WITH CASES AND SELECT WITH COUN…
Postgres Update Multiple Rows with Multiple Returns Preserving Order
So I have a Table A that is missing a relation with Table B such that I want to add the relationship information preserving the order based on insert. Table B can have multiple pieces where UUIDs are unique to a grouping and the order is preserved by and index. So I can have in Table B: What I want