Skip to content

Tag: postgresql

non UNIQUE constraints

So, I got in this situation: I create a table (let say model_a), in this table I have 2 cols (let say col1 and col2). I need a constraint that satisfy this reality: It’s not UNIQUE constraint, you can duplicate the first row. The only one time this constraint active is col1 is the same but col2 is diffe…

PostgreSQL UPDATE statement treats keyword as a column

sorry for the noob question, just getting started with SQL and I have a problem that I could not resolve. Basically, I created a table with “date of birth” column and chose wrong TYPE (integer), so every time I am trying to enter date of birth as “1998-01-04” it is just showing 1998. S…

How to calculate agregate values by condition?

here my base example Try smth like this, but nothing Could you help me? Answer UPDATE: for these, I have added a new column to allow ordering of the rows. As the OP referred to day_name as a number in code, I have assumed that they refer to days – and thus changed the ‘id’ column to ‘d…

Does index help a sql select sorting performance?

I have a SQL statement like this: I think the benefit for indexing ‘createdAt’ column is quite minimal, since it does the select first then sort 3 rows. Am I correct? Or it’s better to add indexing? Answer There are two possible indexing strategies for the query you show: Index the IN condit…