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
Tag: postgresql
POSTGRESQL. Insert or update on table violates foreign key constraint
I am new in Posgresql. I have 5 tables and I am trying to INSERT properties to tables. When I tried to Insert 2nd time, I have this error in ‘pgadmin’. ERROR: insert or update on table “question” …
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…
Golang, database/sql, Postgres – is using QueryRow with an INSERT bad practice when you need the result?
The Go database/sql Postgres adapter does not support LastInsertId. From the docs: pq does not support the LastInsertId() method of the Result type in database/sql. To return the identifier of an INSERT (or UPDATE or DELETE), use the Postgres RETURNING clause with a standard Query or QueryRow call. But the Go…
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…
Use dynamically generated value to check whether a key exists in postgres json
I want to check for keys in my json datatype, where the key is the number of a week. Basically, I use this function to get the number of the next week: extract(week FROM current_date) + 1 Now I want to use the returned value, to check whether this key exists in my object and if not return an empty
Amazon RDS – Postgres not using index for SELECT queries
I have a feeling I am doing something terribly wrong but I can’t seem to figure it out. I have the following query which I am trying to execute: Also, I have an index on day, month, year which I had set up using the following command Now I figured the setting to set sequential scan on/off and tried play…
Postgres pattern matching middle letters of a string
How would I match a name, such that one of the middle letters of the name must come from the word ‘qwerty'(thus containing either of the letters ‘q’, ‘w’ , ‘e’, ‘r’, ‘t’,’y’)? I am curious how you can determine what the middle lette…
How can I use an input from another table in my query?
I’m creating a new table using PostgreSQL, but I need to get a parameter from another table as an input. This is the table I have (I called table_1): id column_1 1 100 2 100 3 100 4 …
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.