Skip to content

Tag: postgresql

Set default value for all columns of a table

I have multiple tables with a lot of columns. Some columns contain Null values. Now, i want to set them to a default value (empty string or 0). I found two two pieces of SQL that probably cover what i need but i can’t put them together. I can use the above code to get all columns and their data

How can I add an object to my table with multiple values?

We have a postgres setup, and I’ll be honest straight away I know very little about database manipulations, my goal is to add an object to the pre-existing table called websites and then have the following object with properties as below: I know it’s quite easy to just add supportDesktop as a bool…

SQL IF statements in transactions

I’m trying to make a condition where if the number of available seats within a given plane is less than zero then ROLLBACK. However, I am receiving a message stating that there is a syntax error at IF (i.e. “syntax error at or near “IF””). Why is this, can I not use if statements…

Count entries by ranges?

I have a table like so: I need query which returns this: Count of users with this sum of amounts(balance) Answer You have to aggregate twice. The first time to SUM amount for each user. The second time to count the number of users for each amount.