I'm using Postgres and I'm trying to write a query like this:
select count(*) from table where datasets = ARRAY[]
i.e. I want to know how many rows have an empty array for a certain column, but postgres doesn't like that:
select count(*) from super_eds where datasets = ARRAY[]; ERROR: syntax error at or near "]" LINE 1: select count(*) from super_eds where datasets = ARRAY[]; ^
To check if an array is empty or not, you can use the . length property. The length property sets or returns the number of elements in an array. By knowing the number of elements in the array, you can tell if it is empty or not.
You can just use a conditional WHERE clause like so: with t as ( <your query here> ) select t.id, t.name, t. randomid, trand.name as randomname from t left join t trand on t. randomid = trand.id where @ids IS NULL OR t.id IN (select item from dbo.
Oracle reads empty strings as NULLs, while PostgreSQL treats them as empty. Concatenating NULL values with non-NULL characters results in that character in Oracle, but NULL in PostgreSQL. Oracle and PostgreSQL behave similarly in many cases, but one way they differ is in their treatment of NULLs and empty strings.
The syntax should be:
SELECT COUNT(*) FROM table WHERE datasets = '{}'
You use quotes plus curly braces to show array literals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With