unnest

using tidyr unnest with NULL values

允我心安 提交于 2019-11-29 20:21:03
问题 I converted a JSON file into a data.frame with a a nested list structure, which I would like to unnest and flatten. Some of the values in the list are NULL, which unnest does not accept. If I replace the NULL values with a data.frame structure that has only NA values, I get the desired result. Below is a simplified example of my problem. I have tried to replace the NULL values with the NA data.frame but did not manage because of the the nested structure. How can I achieve the desired result?

PostgreSQL - text Array contains value similar to

六月ゝ 毕业季﹏ 提交于 2019-11-28 12:38:37
I'm trying to get rows where a column of type text[] contains a value similar to some user input. What I've thought and done so far is to use the 'ANY' and 'LIKE ' operator like this: select * from someTable where '%someInput%' LIKE ANY(someColum); But it doesn't work. The query returns the same values as that this query: select * from someTable where 'someInput' = ANY(someColum); I've got good a result using the unnest() function in a subquery but I need to query this in WHERE clause if possible. WHY doesn't the LIKE operator work with the ANY operator and I don't get any errors? I thought

Parallel unnest() and sort order in PostgreSQL

本秂侑毒 提交于 2019-11-27 09:18:33
I understand that using SELECT unnest(ARRAY[5,3,9]) as id without an ORDER BY clause, the order of the result set is not guaranteed. I could for example get: id -- 3 5 9 But what about the following request: SELECT unnest(ARRAY[5,3,9]) as id, unnest(ARRAY(select generate_series(1, array_length(ARRAY[5,3,9], 1)))) as idx ORDER BY idx ASC Is it guaranteed that the 2 unnest() calls (which have the same length) will unroll in parallel and that the index idx will indeed match the position of the item in the array? I am using PostgreSQL 9.3.3. Erwin Brandstetter Yes, that is a feature of Postgres

Find rows where text array contains value similar to input

。_饼干妹妹 提交于 2019-11-27 06:58:41
问题 I'm trying to get rows where a column of type text[] contains a value similar to some user input. What I've thought and done so far is to use the 'ANY' and 'LIKE ' operator like this: select * from someTable where '%someInput%' LIKE ANY(someColum); But it doesn't work. The query returns the same values as that this query: select * from someTable where 'someInput' = ANY(someColum); I've got good a result using the unnest() function in a subquery but I need to query this in WHERE clause if

Parallel unnest() and sort order in PostgreSQL

空扰寡人 提交于 2019-11-26 17:49:24
问题 I understand that using SELECT unnest(ARRAY[5,3,9]) as id without an ORDER BY clause, the order of the result set is not guaranteed. I could for example get: id -- 3 5 9 But what about the following request: SELECT unnest(ARRAY[5,3,9]) as id, unnest(ARRAY(select generate_series(1, array_length(ARRAY[5,3,9], 1)))) as idx ORDER BY idx ASC Is it guaranteed that the 2 unnest() calls (which have the same length) will unroll in parallel and that the index idx will indeed match the position of the

Split given string and prepare case statement

旧城冷巷雨未停 提交于 2019-11-26 06:08:44
问题 Table : table_name create table table_name ( given_dates timestamp, set_name varchar ); Insertion of records : insert into table_name values(\'2001-01-01\'),(\'2001-01-05\'),(\'2001-01-10\'), (\'2001-01-15\'),(\'2001-01-20\'),(\'2001-01-25\'), (\'2001-02-01\'),(\'2001-02-05\'),(\'2001-02-10\'), (\'2001-02-15\'); Now I want to update set_name for some dates. For example : I want to update table like this: given_dates set_name ---------------------- 2001-01-01 s1 2001-01-05 s1 2001-01-10 s2