set-returning-functions

Join against the output of an array unnest without creating a temp table

余生长醉 提交于 2021-01-27 06:38:27
问题 I have a query in a UDF (shown below) which unnest() s an array of integers and joins against it, I have created a local temp table in my pgplsql UDF since I know this works. Is it possible to use unnest directly in a query to perform a join instead of having to create a temp table ? CREATE OR REPLACE FUNCTION search_posts( forum_id_ INTEGER, query_ CHARACTER VARYING, offset_ INTEGER DEFAULT NULL, limit_ INTEGER DEFAULT NULL, from_date_ TIMESTAMP WITHOUT TIME ZONE DEFAULT NULL, to_date_

Error while using regexp_split_to_table (Amazon Redshift)

﹥>﹥吖頭↗ 提交于 2020-01-10 02:03:28
问题 I have the same question as this: Splitting a comma-separated field in Postgresql and doing a UNION ALL on all the resulting tables Just that my 'fruits' column is delimited by '|'. When I try: SELECT yourTable.ID, regexp_split_to_table(yourTable.fruits, E'|') AS split_fruits FROM yourTable I get the following: ERROR: type "e" does not exist Q1. What does the E do? I saw some examples where E is not used. The official docs don't explain it in their "quick brown fox..." example. Q2. How do I

Error while using regexp_split_to_table (Amazon Redshift)

≯℡__Kan透↙ 提交于 2020-01-10 02:03:13
问题 I have the same question as this: Splitting a comma-separated field in Postgresql and doing a UNION ALL on all the resulting tables Just that my 'fruits' column is delimited by '|'. When I try: SELECT yourTable.ID, regexp_split_to_table(yourTable.fruits, E'|') AS split_fruits FROM yourTable I get the following: ERROR: type "e" does not exist Q1. What does the E do? I saw some examples where E is not used. The official docs don't explain it in their "quick brown fox..." example. Q2. How do I

How to select multiple rows filled with constants in Amazon Redshift?

社会主义新天地 提交于 2020-01-03 08:14:14
问题 I have already tried the common PostgreSQL answer, but seems like it doesn't work with Redshift: SELECT * FROM VALUES (1) AS q (col1); ERROR: 42883: function values(integer) does not exist I need this because for some reason I can't use UNION ALL . Any help will be greatly appreciated. 回答1: The correct Postgres syntax would be: SELECT * FROM ( VALUES (1) ) AS q (col1); A set of parentheses was missing. But it seems Redshift does not even support a VALUES expression outside of INSERT (like

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 |

Find duplicated values on array column

删除回忆录丶 提交于 2019-12-20 02:57:13
问题 I have a table with a array column like this: my_table id array -- ----------- 1 {1, 3, 4, 5} 2 {19,2, 4, 9} 3 {23,46, 87, 6} 4 {199,24, 93, 6} And i want as result what and where is the repeated values, like this: value_repeated is_repeated_on -------------- ----------- 4 {1,2} 6 {3,4} Is it possible? I don't know how to do this. I don't how to start it! I'm lost! 回答1: Use unnest to convert the array to rows, and then array_agg to build an array from the id s It should look something like

Unnest multiple arrays in parallel

匆匆过客 提交于 2019-12-17 02:52:12
问题 My last question Passing an array to stored to postgres was a bit unclear. Now, to clarify my objective: I want to create an Postgres stored procedure which will accept two input parameters. One will be a list of some amounts like for instance (100, 40.5, 76) and the other one will be list of some invoices ('01-2222-05','01-3333-04','01-4444-08') . After that I want to use these two lists of numbers and characters and do something with them. For example I want to take each amount from this

Unnest multiple arrays in parallel

北战南征 提交于 2019-12-17 02:52:06
问题 My last question Passing an array to stored to postgres was a bit unclear. Now, to clarify my objective: I want to create an Postgres stored procedure which will accept two input parameters. One will be a list of some amounts like for instance (100, 40.5, 76) and the other one will be list of some invoices ('01-2222-05','01-3333-04','01-4444-08') . After that I want to use these two lists of numbers and characters and do something with them. For example I want to take each amount from this

Return list with dates within a specified range from a single query

有些话、适合烂在心里 提交于 2019-12-11 21:25:06
问题 I'm trying to obtain a list of dates within range, similar to the command NOW() in PostgreSQL, with the only difference that now() , returns only the current date. If I execute it as follows I obtain: select now(); 2013-09-27 15:27:50.303-05 Or by example, I could do this: select now() - interval '1' day; and the result is yesterday 2013-09-27 15:27:50.303-05 What I need is a query that could return a list with every date within a given range, so if I provide 2013-09-20 and 2013-09-27 (I'm

Return Multiple Values from Oracle Function

独自空忆成欢 提交于 2019-12-11 15:28:04
问题 I want to create a function that returns multiple rows into a table that is of object type. I have created an object and a nested table object and now when I run the function there is an error which says PL/SQL: SQL Statement ignored PL/SQL: ORA-00947: not enough values -- Object type creation create or replace type test_object_sn as object ( column_1 varchar2(30), column_2 varchar2(30), column_3 number ); -- Table of object create or replace type test_otable_sn as table of test_object_sn; --