unnest

tidyr::unnest() with different column types

故事扮演 提交于 2020-05-15 10:15:42
问题 Since the update to tidyr version 1.0.0 I have started to get an error when unnesting a list of dataframes. The error comes because some of the data frames in the list contain a column with all NA values (logical), while other of the dataframes contain the same column but with some character values (character). The columns with all NA values are coded as logicals while the others are coded as character vectors. The default behavior of earlier versions of tidyr handled the different column

tidyr::unnest() with different column types

你。 提交于 2020-05-15 10:14:05
问题 Since the update to tidyr version 1.0.0 I have started to get an error when unnesting a list of dataframes. The error comes because some of the data frames in the list contain a column with all NA values (logical), while other of the dataframes contain the same column but with some character values (character). The columns with all NA values are coded as logicals while the others are coded as character vectors. The default behavior of earlier versions of tidyr handled the different column

IN Linux Distinct SQL is not working with UNNEST

做~自己de王妃 提交于 2020-01-22 02:11:09
问题 When i run this query in window system behave correctly UNNSET but when i run this query Linux behave different.unnset duplicate record list on different row SELECT DISTINCT "billing_billmanagement"."creation_date", "billing_billmanagement"."bill_number", unnest(array_agg(DISTINCT "inventory_product"."product_name")) AS "product", unnest(array_agg(DISTINCT "services_service"."name")) AS "service" FROM "billing_billmanagement" INNER JOIN "users_staffuser" ON ("billing_billmanagement"."staff_id

Postgres FROM query with one of the column name

萝らか妹 提交于 2019-12-24 05:57:29
问题 As follow-up to the previous question: Count matches between multiple columns and words in a nested array I have the following query: SELECT row_number() OVER (ORDER BY t.id) AS id , t.id AS "RID" , count(DISTINCT a.ord) AS "Matches" FROM tbl t LEFT JOIN ( unnest(array_content) WITH ORDINALITY x(elem, ord) CROSS JOIN LATERAL unnest(string_to_array(elem, ',')) txt ) a ON t.description ~ a.txt OR t.additional_info ~ a.txt GROUP BY t.id; which gives me matches correctly, but now the value for

Postgres FROM query with one of the column name

≡放荡痞女 提交于 2019-12-24 05:57:06
问题 As follow-up to the previous question: Count matches between multiple columns and words in a nested array I have the following query: SELECT row_number() OVER (ORDER BY t.id) AS id , t.id AS "RID" , count(DISTINCT a.ord) AS "Matches" FROM tbl t LEFT JOIN ( unnest(array_content) WITH ORDINALITY x(elem, ord) CROSS JOIN LATERAL unnest(string_to_array(elem, ',')) txt ) a ON t.description ~ a.txt OR t.additional_info ~ a.txt GROUP BY t.id; which gives me matches correctly, but now the value for

SQL multiple UNNEST in single select list

大憨熊 提交于 2019-12-23 10:29:04
问题 I was implementing a Query system. I implemented unnest function. Now user was asking about using multiple unnest in a single select statement. I was using PostgreSQL as kind of guideline since most users was using it before our query system. PostgreSQL has such strange behavior: postgres=# select unnest(array[1,2]), unnest(array[1,2]); unnest | unnest --------+-------- 1 | 1 2 | 2 (2 rows) postgres=# select unnest(array[1,2]), unnest(array[1,2,3]); unnest | unnest --------+-------- 1 | 1 2 |

“Unnesting” a dataframe in R

 ̄綄美尐妖づ 提交于 2019-12-12 20:08:19
问题 I have the following data.frame : df <- data.frame(id=c(1,2,3), first.date=as.Date(c("2014-01-01", "2014-03-01", "2014-06-01")), second.date=as.Date(c("2015-01-01", "2015-03-01", "2015-06-1")), third.date=as.Date(c("2016-01-01", "2017-03-01", "2018-06-1")), fourth.date=as.Date(c("2017-01-01", "2018-03-01", "2019-06-1"))) > df id first.date second.date third.date fourth.date 1 1 2014-01-01 2015-01-01 2016-01-01 2017-01-01 2 2 2014-03-01 2015-03-01 2017-03-01 2018-03-01 3 3 2014-06-01 2015-06

Postgresql - Opposite of string_agg

吃可爱长大的小学妹 提交于 2019-12-12 12:07:17
问题 I'm looking for a postgresql function that will do the opposite of string_agg . I have a movies table where the tags column contains values such as Action|Adventure|Drama|Horror|Sci-Fi Action|Horror|Sci-Fi I would like to get a distinct list of tags from this column, for example Action Adventure Drama Horror Sci-Fi 回答1: You can use unnest() and string_to_array() : select unnest(string_to_array(t.col, ',')) from t 回答2: You need string_to_array() combined with unnest() select t.tag from movies,

BigQuery Unnest an Array - Getting dupliates

浪尽此生 提交于 2019-12-11 17:56:52
问题 Im working on GCP Billing queries in BQ. But while extracting array with the cost I'm getting wrong values like unnest returns array elements in row format. So if I have 2 elements in an array for a single row then I'll get 2 rows. EG: Actual Array: SELECT TO_JSON_STRING(labels), cost FROM billing_export.gcp_billing_export WHERE _PARTITIONTIME >= "2018-08-01 00:00:00" AND _PARTITIONTIME < "2018-09-01 00:00:00" AND billing_account_id = "xxx-62378F-xxx" AND TO_JSON_STRING(labels) = '[{"key":

SQL Query to Transpose Column Counts to Row Counts

本小妞迷上赌 提交于 2019-12-08 14:16:01
问题 I have a table that looks like the following which shows the count of types. I need to and have been trying to display data as 1 column and 7 rows instead though... without success. __________________________________________________________________________ | col types | win2k | winxp | win2k3 | vista | win7 | win8 | win8.1 | -------------------------------------------------------------------------- | count of types | 2365 | 65655 | 422445 | 4822 | 482 | 2331 | 485323 | -----------------------