I have an original table (TABLE 1): A B C D 1 3 5 7 2 4 6 8 I want to add column F from the table below (Table 2) onto table 1: A F G H 1 29 5 7 2 30 6 8 As well as adding Column J,L and O from the table below (Table 3)
Tag: postgresql
SQL write a query, question from interview problem
At the beginning I need to mention that I am not very good at SQL so I would like to ask you. Here is a tables relation: tables What I need to do with them is “Show name, surname and number of movies those directors (Reżyser means director), who made more movies that the average number is for all directors.
Get distinct sets of rows for an INSERT executed in concurrent transactions
I am implementing a simple pessimistic locking mechanism using Postgres as a medium. The goal is that multiple instances of an application can simultaneously acquire locks on distinct sets of users. The app instances are not trying to lock specific users. Instead they will take any user locks they can get. Say, for example, we have three instances of the
How to rotate a two-column table?
This might be a novice question – I’m still learning. I’m on PostgreSQL 9.6 with the following query: My query returns the following dynamic rows: locales count en 10 fr 7 de 3 n additional locales (~300)… n-count I’m trying to rotate it so that locale values end up as columns with a single row, like this: en fr de
How to separate column values by condition (pivot) to fill one row
I have two tables that I’d like do a full outer join where the resulting view separates the values table into two separate columns with one row for each name_id. I have made one approach with a CASE expression to select by type and then use it with pandas to fill in the values and return distinct name_ids. Name Table
How to obtain row for minimum date for a value that is equal to the value in maximum date, per group?
I am trying to obtain row for a query.. where row value1, value2 in minimum end_date is equal to the max end_date, per group of id’s. My current query only obtains the row value1, value2 from the max end_date in the query result: This result obtains the most recent record, but I’m looking to obtain the row where value1 &
Execute same query multiple times with different parameter postgressql
I don’t know how to easily explain what i need to do but i’ll try. Lets say i have a user table with 5 users. instead of just do a select * from users i need to do this different and more difficult. I need to build a query that for each row in users table runs a query with
When do Postgres transactions fail?
I was wondering at what point a transaction actually fails in Postgres. By this I mean stop working, and return an error. Is it after the first failed query? Does it try all queries and then return failure? Hopefully it fails fast on first failed query, but I don’t know for sure. For instance, if I have a transaction with
SQL Query: finding cheapest car by company
Following YouTube tutorial “Learn PostgreSQL Tutorial – Full Course for Beginners”, I replicate teacher’s code but yields different result and cannot figure out why. Table is this simple: and so on, 1000 entries. Querying cheapest model from manufacturer, tutorial says: And it works properly, returning as many entries as distinct car makers. But when I run it in my PostgreSQL
How to specify information from the table being inserted on PostgreSQL upsert?
I am trying to insert values from a temporary table (NewThings) with columns Thing and Counts into my main table (MyThings) with columns Thing and Count. If a thing does not exist in the main table I want to insert a new row, otherwise I want to add to the counter. However, I am struggling with the correct syntax on