I want to GROUP by data by time range. The example I have start_date and end_date, and I want the separate range between start_date and end_date on 25 range and get sum value from 1 to 25. Simple presentation of my table: table t1 have: generate_series function to separate on and sum by how this 25 for 2019-1…
Tag: postgresql
Get all days in a month excluding weekends postgresql
I want to write a query sql for postgresql that can basically return me all days of a month excluding weekends. For example (For 11/2019) : First Week: 11/1 Second Week : 11/4 -> 11/8 Third Week : 11/11 -> 11/15 Fouth Week : 11/18 -> 11/22 Fifth Week : 11/25 -> 11/29 I can’t find any postgre…
Get the dates of two weeks from today from database
I have some dates in postgresql database. I want to find dates from today to next two weeks or 14 days. How i can find the dates between current date and next 14 days? This query is not working. I …
Column concatenation in Order by expression. Is it wrong?
What are pros and cons whether I use Order by expression like this: or in this way: How each one does impact on performance? Answer The concatenation is unnecessary and may produce incorrect results. For instance, consider these values: The concatenation will put the first row first. By individual keys, it wi…
How to check if a varchar contains an upper case char in postgreSQL?
I have another Question comming up, while solving some problems with postgreSQL. Is there any option, to check (in a check statement), if a varchar() contains an upper case character? (I want that my table only holds Strings with at least one upper case letter.) Thats how my table look: Does anyone have a tip…
use concat or replace for values in the middle SQL / Postgresql
how to use concat for values in the middle, I have the following data and I want to change it to be like this I tried with a query like this, but the results did not match what I expected this is the result of my query Answer You can simply use
Postgresql Select and display one column based on another column
WALLET TABLE ID IS_SPEND HOWMUCH true. 500 false. 1000 true. 5 I want to calculate how much money I have after several transactions. spend as spend money and not spend as earn money I tried But it cannot reach my goal. I don’t know how can I get the result I want, just output 495 is perfect. Answer You …
SQL select the latest record on joined tables
I want to retrieve the property which an user paid a tax last. have two tables person_properties and property_taxes What I tried so far: This gives me the person_id along the max year. But I actually need the property_id, the property which an user paid last. If I replace pp.person_id by pp.property_id, I the…
Create SQL command with a query parameter that checks for NULL but also for other values
I am trying to write a dynamic SQL command using Python / Postgres. In my where clause I want to use a query parameter (which is user defined) that has to look for NULL values within a code column (varchar), but in other cases also for specific numbers. If I have to check for a certain value I use this:
Are postgresql `SELECT DISTINCT` queries deterministic?
Are Postgres SELECT DISTINCT queries deterministic? Will SELECT DISTINCT somecolumn FROM sometable return the same result (including order) if the table (and entire database) goes unchanged? In the Select Query Documentation the Description section notes: If the ORDER BY clause is specified, the returned rows…