Skip to content

Tag: postgresql

In SQL, how do I prevent array elements from being null?

I’m designing a SQL database and I’d like to make sure my schema is as strict as possible. Is there a way to require that an array column doesn’t contain null elements? As I understand it, I can make the whole column NOT NULL, but that’s not the same thing since an array of null elemen…

Default values for each key in a where-clause

Given a table: I need to set 0 for every ID in where-clause along with IDs: Result What query can I use here? Upd1: let it be Postgres. Upd2: can I do it without joins? Answer You didn’t mention your DBMS, but the following is standard ANSI SQL: It’s possible without a join, but that doesn’t…

Appending Name based on Min and Max datetime

I have Event_No, Events, Date Range in my table like below. I need to show Min datetime respective Event name with ‘IN'(a concatenation of (Event-‘IN’))and Max datetime respective Event with Out(a concatenation of (Event-‘Out’)). I need My Final Output like below Thanks Answer Th…