I’m using the following logic in my where statement. If I do just the statement below then it returns results However if I expand on the where logic to the following statement it returns no results. Why? Shouldn’t it return the same thing as where statement above? Basically what I want is the foll…
Tag: postgresql
Roll up multiple rows into one postgresql
There is a role table How do I get the output as using SQL query : Answer Please try below query for your problem and let me know if still you are facing any issue.
Postgres Import from different table
I’m still fairly new to postgres. I have a table named: university_table with fields: name, nationality, abbreviation, adjective, person. I found this sql query to insert data from: https://stackoverflow.com/a/21759321/9469766 Snippet of query below. How can alter the query to insert these values into m…
Writing a Rails migration to collapse booleans into an enum
I made a mistake when modeling my data and created a model with 4 booleans, only one of which are active at a time. I want to create a column of Postgres enum type, and then set the value based on …
If statement with select in Postgresql
I’ve having trouble to do a if with select, e.g: In SQL Server I can do this: But in postgresql I don’t have any idea how handle this. I’ve tring some ways to do this, but unfortunately I have not success. Answer The syntax for an IF in Postgres (or rather PL/pgSQL) is IF … THEN ……
Counting users based on an event count
I have an events table where I currently have a count of users grouped by the date. I am wanting to make two different counts based on the number of times a user had a specific event (we’ll call it event_a) The first count will count the user if event_a appeared exactly 1 time for the user, the 2nd coun…
PostgreSQL multiple join
I would like to make multiple joins in one query, I have four tables for that with the following structure: Table 1 fields, t1: did (int), finished (datetime), userid (int) Table 2 fields, t2: userid …
How to retrieve SQL Error message with Hibernate
I have developed a small application accessing a PostgreSQL database with Hibernate. When I try to delete a record involved in a foreign key with another table, a javax.persistence….
IntelliJ IDEA does not recognise specific database schema in Javascript/Typescript files
At some point I was amazed when I managed to set the support of specific schema in my nodejs modules. Unfortunately, later IntelliJ IDEA decided to crash and I needed to remove my .idea folder, thus I lost all of my configurations. So, the problem is that when I write SQL queries it does not find tables or fu…
date time comparison with > does not work
I have two SQL statements: 1) (now i use this) 2) (but i need to use this) first query return 11 lines query 2 return 388. my observation (about query 2) is that instead of “2019-11-26 13:20:00” it is taken “2019-11-26” and when I replace it really returns the same answer date_occured …