Skip to content

Tag: postgresql

Increase or decrease customer credits in upsert

In my app customers can build up credit in different categories and then spend it on things the relevant table looks like this: There is one entry for every category in which a user has credit There are 2 constraints, one to make sure the amount is never negative and there is only one user category connection…

How to check for column attributes in postgreSQL?

I am new to SQL. Let say that when someone created a table like this in database named test1 of PostgreSQL: I make a query to the database and do not know how data in columns are stored. Is there a query to return the stored definition of the columns in the users table or a method to check this

Postgresql conditional script

I need to update the column (vendor_type) in the table depending on values in other columns. Table name = “vendor” Columns = “client_id”(varchar), “coach_id”(varchar), “exm_vendor”(boolean), “vendor_type”(varchar) And this is what I want to do with p…

Obtain Name Column Based on Value

I have a table that calculates the number of associated records that fit a criteria for each parent record. See example below: note – morning, afternoon and evening are only weekdays What I am trying to achieve is to determine which columns have the lowest value and get their column name as such: Here i…

Postgresql OVER

I have data like: id user index 1 aaa 0 2 bbb 0 3 aaa 1 4 bbb 1 5 aaa 2 6 ccc 0 How to get only the latest index of each user ? Like this result id user index 4 bbb 1 5 aaa 2 6 ccc 0 Answer Looks like a simple DISTINCT ON: This will