Oracle: How to retrieve a NULL row - oracle10g

I tried to extract the row which doesn't have any value in the timestamp column.
select * from user_details where lastlogin_time = null;

Related

How to select empty paths with POSTGRES LTREE

I have a simple table defined in Postgres, where I'm using LTREE, but some rows can have empty paths:
CREATE TABLE films (
id serial PRIMARY KEY,
title varchar(40) NOT NULL,
path ltree DEFAULT NULL
);
If I insert the following values into the table,
INSERT INTO films (title, path)
VALUES ('first', 'A'),('second', 'A.B'),('third', NULL);
then try to select the rows with empty paths,
SELECT * FROM films WHERE path=NULL;
I get empty rows:
id | title | path
----+-------+------
(0 rows)
How should I modify the query to return rows with empty paths? Thanks!
The result of comparison operation with at least one operand is NULL always returns NULL. Thus your predicate where path = null always returns null, but the to select a row the expression must return True. Use instead:
SELECT * FROM films WHERE path is NULL;

Select * with result columns that only contain values

postgresql
--I don't want to have to enter each repeating column, I want syntax in the where clause that checks all the columns and returns only columns with data
SELECT *
FROM table_with_200_columns
where datetime between '2021-01-01' and current_date
and column.1 is not null
and column.1 <>''
and column.2 is not null
and column.2 <>''
and column.3-200 is not null
and column.3-200 <>''
;
--something like this with an "presently unknown function" as in the example of 'allofthemtherecolumns'
SELECT *
FROM table_with_200_columns
where datetime between '2021-12-01' and current_date
and allofthemtherecolumns is not null
and allofthemtherecolumns <>''
your assistance is greatly appreciated
You can transform a row into an hstore record, then extract just the values and look if none of them is null
select * from t
where false = ALL (SELECT unnest(avals(hstore(t))) IS NULL);
PS: you would need the hstore extension
Convert the table row to json, remove datetime and all null/blank valued key, then check it's not empty:
select *
from table_with_200_columns
where datetime between '2021-01-01' and current_date
and regexp_replace(jsonb_strip_nulls(to_jsonb(table_with_200_columns) - 'datetime')::text, '"[^"]+":"",?', '', 'g') != '{}'

Postgresql: how to return a single column request as an integer array

I would like to create a function that returns a column of a table as an integer array.
In other words, how can I transfrom the result of SELECT id FROM mytable to integer[] ?
You can do:
SELECT ARRAY(SELECT id FROM mytable)
Or:
SELECT array_agg(id) FROM mytable

updating a varchar column with multiple select stmts

I have to update a VARCHAR column of a table by concatenating values from SELECT queries from another table. I have build a query like
UPDATE url SET VALUE = (SELECT id FROM ids WHERE identifier='site')':'(SELECT id FROM cids WHERE identifier='cid')
WHERE name='SToken:CToken'
AND tokenvalue LIKE (SELECT id FROM ids WHERE identifier='site');
Here value is VARCHAR.
How should I do this?

PostgreSQL Text column to integer column

I have to convert one text column to integer column.
Showed code work when I have text (all numbers) in fields but now I find some empty strings '' where query stops.
ALTER TABLE mytable
ALTER COLUMN mycolumn TYPE integer USING (TRIM(mycolumn)::integer);
Can here be done so that empty strings be converted to integer 0 so this query will pass?
How to do this?
You can update your values before altering table:
UPDATE mytable SET mycolumn = '0' WHERE mycolumn = '';