Re: ***SPAM*** Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Pavel Stehule
2010/3/29 Andrus : >> If renaming the function makes it appear to work differently, >> then there is another function of similar name in there somewhere. >> I'm betting the server is not 8.1 after all. > > I'm using > > "PostgreSQL 8.4.1, compiled by Visual C++ build 1400, 32-bit" > oh sorry, you

Re: ***SPAM*** Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Andrus
If renaming the function makes it appear to work differently, then there is another function of similar name in there somewhere. I'm betting the server is not 8.1 after all. I'm using "PostgreSQL 8.4.1, compiled by Visual C++ build 1400, 32-bit" Andrus. -- Sent via pgsql-general mailing list

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Tom Lane
Pavel Stehule writes: > 2010/3/29 Tom Lane : >> I think if it appeared to work before it was because the built-in >> unnest() function was capturing the call. > he uses 8.1. the bug is in "generate_series(1,>>>4<<<)" If renaming the function makes it appear to work differently, then there is ano

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Pavel Stehule
sql; > > select unnest21(string_to_array('23,2,3,4,5',',')); > > Andrus. > > - Original Message - From: "Tom Lane" > To: "Andrus" > Cc: "Pavel Stehule" ; > > Sent: Monday, March 29, 2010 6:00 PM > Subject:

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Tom Lane
"Andrus" writes: > I changed unction name and tried: > CREATE OR REPLACE FUNCTION unnest21(anyarray) > RETURNS SETOF anyelement as $$ > SELECT $1[i] FROM generate_series(1,4) g(i) > $$ LANGUAGE sql; > select unnest21(string_to_array('23,2,3,4,5',',')); > In this case it returns only 4 rows. >

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Pavel Stehule
2010/3/29 Tom Lane : > "Andrus" writes: >> I changed unction name and tried: >> CREATE OR REPLACE FUNCTION unnest21(anyarray) >> RETURNS SETOF anyelement as $$ >>   SELECT $1[i] FROM generate_series(1,4) g(i) >> $$ LANGUAGE sql; > >> select unnest21(string_to_array('23,2,3,4,5',',')); > >> In this

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Pavel Stehule
2010/3/29 Andrus : > Pavel > > thank you. > How to add word wrap to this at some column between words ? > For example string > '  ' > > if word wrap is at column 12 should produce table with two rows: > > >   > You can't do it. This working only for one column.

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Andrus
" ; Sent: Monday, March 29, 2010 6:00 PM Subject: Re: [GENERAL] Splitting text column to multiple rows "Andrus" writes: Pavel, pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); unnest 23 2 3 4 (4 rows) Result is wron

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Andrus
ea what is happening. Andrus. - Original Message - From: "Tom Lane" To: "Andrus" Cc: "Pavel Stehule" ; Sent: Monday, March 29, 2010 6:00 PM Subject: Re: [GENERAL] Splitting text column to multiple rows "Andrus" writes: Pavel, pa...@postgres:548

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Andrus
Pavel thank you. How to add word wrap to this at some column between words ? For example string ' ' if word wrap is at column 12 should produce table with two rows: Andrus. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Tom Lane
"Andrus" writes: > Pavel, >> pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); >> unnest >> >> 23 >> 2 >> 3 >> 4 >> (4 rows) > Result is wrong: it must contain 5 rows. Surely that's a copy-and-paste mistake? I get 5 rows from this example.

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Pavel Stehule
2010/3/29 Andrus : > Pavel, > >> CREATE OR REPLACE FUNCTION unnest(anyarray) >> RETURNS SETOF anyelement as $$ >>  SELECT $1[i] FROM generate_series(1,4) g(i) >> $$ LANGUAGE sql; >> >> pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); >> unnest >> >> 23 >> 2 >> 3 >> 4

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Andrus
Pavel, CREATE OR REPLACE FUNCTION unnest(anyarray) RETURNS SETOF anyelement as $$ SELECT $1[i] FROM generate_series(1,4) g(i) $$ LANGUAGE sql; pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); unnest 23 2 3 4 (4 rows) Result is wrong: it must contain 5 rows. Ho

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Pavel Stehule
2010/3/29 Andrus : >> no it is in same order. generate_series generates indexes from > > 1,2,3 so result have to be exactly in same order. You do some > wrong. > > In my sample I used joind and projecton this changes order. > How to add order number 1,2,.. to created table ? > you cannot use j

Re: [GENERAL] Splitting text column to multiple rows

2010-03-29 Thread Andrus
no it is in same order. generate_series generates indexes from 1,2,3 so result have to be exactly in same order. You do some wrong. In my sample I used joind and projecton this changes order. How to add order number 1,2,.. to created table ? Andrus. -- Sent via pgsql-general mailing list (

Re: [GENERAL] Splitting text column to multiple rows

2010-03-28 Thread Pavel Stehule
2010/3/28 Andrus : >> CREATE OR REPLACE FUNCTION unnest(anyarray) >> RETURNS SETOF anyelement as $$ >>  SELECT $1[i] FROM generate_series(1,4) g(i) >> $$ LANGUAGE sql; >> >> pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); > > I tried code below. Order of rows in result is di

Re: [GENERAL] Splitting text column to multiple rows

2010-03-28 Thread Andrus
CREATE OR REPLACE FUNCTION unnest(anyarray) RETURNS SETOF anyelement as $$ SELECT $1[i] FROM generate_series(1,4) g(i) $$ LANGUAGE sql; pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); I tried code below. Order of rows in result is different from the order of elements i

Re: [GENERAL] Splitting text column to multiple rows

2010-03-28 Thread Pavel Stehule
Hello try: CREATE OR REPLACE FUNCTION unnest(anyarray) RETURNS SETOF anyelement as $$ SELECT $1[i] FROM generate_series(1,4) g(i) $$ LANGUAGE sql; pa...@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',',')); unnest 23 2 3 4 (4 rows) regards Pavel Stehule 2010/3/28

[GENERAL] Splitting text column to multiple rows

2010-03-28 Thread Andrus
TEXT column contains multi-line text. How to split it to multiple rows so that every line is in separate row ? Code below should return two rows, Line 1 Line 2 Solution should work starting at 8.1 Should generate_series or pgsql procedure used or any other idea? Andrus. create temp table tes