Skip to content
Advertisement

Tag: postgresql

Using the function SPLIT_PART twice in PostgreSQL?

I have a TEXT column where each text is formatted as such: /customers/{customer_id}/views/{id1}~{id2}/ I am trying to fetch the id2 only. My idea is how to split the string by the / character first, where I will have: customers, {customer_id}, views, {id1}~{id2}. And then, get the last position: {id1}~{id2}. And then split it again by the ~ character, and finally

How to compose Django Model Filter for relation existence?

There is a many-to-many relationship between A and B. There are 3 tables to represent that relationship. TableA, TableB, TableAB Now I have another table TableC where it has a foreign key to TableA, and I want to filter objects from TableC where it has a relationship with TableB. The following is high-level code to give you the idea how

How to use Peewee to make CASE SQL queries?

I have a table in postgres that holds a priority integer for each row. The priority needs to update whenever I add a new row or change the priority of an existing one for all of the other rows in the table. One way to do it in pure SQL would be with a CASE query: Question: How can I

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

Nest Postgresql Sequelize one-to-one Error with ForeignKey

My Table Has one-to-one connection with table But when i try add some data in second table< i got an Error – Nest error insert or update on table “checkingResults” violates foreign key constraint “checkingResults_resultId_fkey” What happened? I try any thing… And how i remember – a don’t get this error before in this place, i don’t touch something in

sql query that depends on each value of other table

I’m not used to query sentences and this one is a bit tricky, I don’t know even if it is possible (at least with just a single sql query) or if I should change the question name to something more accurated, if so let me know. I have two tables, I will make them simple. The first one that is

SQL WHERE condition when one does not return true, then try other

I have to query a table based on two fields such that if first field matches then don’t check the second but if first field does not match then check if second field matches for a value something like: But if first condition succeeds, it must not check for second condition Example: Suppose the following is my table on querying

Advertisement