Skip to content

Tag: postgresql

Update a field in a JSON column in PostgreSQL

I have a work_item table that has the following schema and a document_type table with the following schema: The data column is a json column that has a Type field. This is a sample column data: I need to update data columns whose data_type column value is DocumentModel and Type field values matches a value in…

Postgres on conflict do update on composite primary keys

I have a table where a user answers to a question. The rules are that the user can answer to many questions or many users can answer one question BUT a user can answer to a particular question only once. If the user answers to the question again, it should simply replace the old one. Generally the on conflict…

How to change the position of column in postgresql without dumping

I know the only workaround is to dump the table and then recreate the whole database with correct positioning of the required columns. But the problem is one of the columns is a foreign key to many tables in the database so it would not be possible to just delete the whole table. Also I cannot delete any colu…

SQL: Running Total of Occurrences

I am using Metabase with a PostgreSQL implementation. I’d like to achieve the outcome in the photo. I wish to include a column that counts how many times a field has occurred above. It should include the current instance as well. Other examples I’ve seen have simply counted total occurrences. As I…