Skip to content

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}. …

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 s…

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…