Re: [SQL] Returnd Refcurser ( not fetchable

2007-08-09 Thread Christian Kindler
Ohhh Yes! Thanks al lot. Sometimes you can't see the wood for the trees. Thanks! Chris Original-Nachricht Datum: Fri, 10 Aug 2007 00:31:03 -0600 Von: Michael Fuhr <[EMAIL PROTECTED]> An: Christian Kindler <[EMAIL PROTECTED]> CC: "Penchalaiah P." <[EMAIL PROTECTED]>, pgsql-sq

Re: [SQL] Returnd Refcurser ( not fetchable

2007-08-09 Thread Michael Fuhr
On Fri, Aug 10, 2007 at 08:16:28AM +0200, Christian Kindler wrote: > select * from getfoo('M'); > -- fetch all in ''; > > ERROR: syntax error at or near "''" at character 15 The cursor name is an identifier so use double quotes instead of single quotes. Also, when using non-holdable cursors you

Re: [SQL] Returnd Refcurser ( not fetchable

2007-08-09 Thread Tom Lane
"Christian Kindler" <[EMAIL PROTECTED]> writes: > fetch all in ''; > ERROR: syntax error at or near "''" at character 15 I think you need double quotes not single quotes here. regards, tom lane ---(end of broadcast)--- TIP

Re: [SQL] Returnd Refcurser ( not fetchable

2007-08-09 Thread Christian Kindler
Sorry but this didn't help ... Can not return next ... so I changed the returns as too but same effect as the first function: drop table foo; create table foo(sirname text, name text); insert into foo values ('Mueller', 'Marcus'); drop function getfoo(char(1)); create or replace function getfoo

Re: [SQL] Returnd Refcurser ( not fetchable

2007-08-09 Thread Penchalaiah P.
create table foo(sirname text, name text); insert into foo values ('Mueller', 'Marcus'); create function getfoo(char(1)) returns refcursor as ' declare ref refcursor; begin open ref for select * from foo where sirname like ''%'' || $1 || ''%''; return next ref; return end; ' LANGUAGE

[SQL] Returnd Refcurser ( not fetchable

2007-08-09 Thread Christian Kindler
Hi! I have the Problem, that a function returns a refcursor and I am not able to fetch them. I tried in several ways. Can you please tell me how to get the cursor data. Thanks Chris PS this is what I have: create table foo(sirname text, name text); insert into foo values ('Mueller', 'Marcus

[SQL] pg_trgm installation

2007-08-09 Thread Arindam Hore
Hello, While installing pg_trgm for the similarity I am unable to install that properly and giving error messages. ./Makefile: line 2: PG_CPPFLAGS: command not found ./Makefile: line 4: MODULE_big: command not found ./Makefile: line 5: OBJS: command not found ./Makefile: line 7: DATA_bui

[SQL] Indexing a field of type point

2007-08-09 Thread David Cottingham
Hi, I realise this isn't strictly an SQL question, but I figured this list might be better suited than the general one. Please let me know if not. I have a table containing a field named location, of type point, i.e. a position in two dimensions. The table has several million records in, and

[SQL] Using function like where clause

2007-08-09 Thread Ranieri Mazili
Hello, I have 2 questions. 1) Can I use a function that will return a string in a where clause like bellow? select * from table where my_function_making_where() and another_field = 'another_think' 2) Can I use a function that will return a string to return the list of columns that I

[SQL] Best Fit SQL query statement

2007-08-09 Thread Kiran
All, Could anyone help me in writing Best Fit SQL statement. Suppose we have table t1 with coloumn t1 (text) with following rows. 98456 98457 9845 9846 984 985 98 99 and if I query on 98456 the result must be 98456, However if I query on 98455 the result must be 9845 and If I query 9849 the res

Re: [SQL] Race condition in resetting a sequence

2007-08-09 Thread Lew
Steve Midgley writes: The code I provided to reset a primary key sequence is actually part of Ruby on Rails core library - actually they use something very similar to what I originally sent: ... SELECT setval('#{sequence}', (SELECT COALESCE(MAX(#{pk})+(SELECT increment_by FROM #{sequence}), (S

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Gregory Stark
"Andreas Joseph Krogh" <[EMAIL PROTECTED]> writes: > Ooops, just fugured that out. But - it still doesn't use the index if I > remove > the "varchar_pattern_ops". I solved it by adding a function: Hm, well it does for me, you would have to post your explain analyze to see what's going on. > An

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Tom Lane
Andreas Joseph Krogh <[EMAIL PROTECTED]> writes: > I forgot to mention: I use UTF-8. IIRC, it works fine with C-locale without > the "varchar_pattern_ops", which is why it works for you I think. That shouldn't make any difference, and doesn't for me in testing here: regression=# select version();

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Tom Lane
Andreas Joseph Krogh <[EMAIL PROTECTED]> writes: >> Another question then: Why doesn't "varchar_pattern_ops" handle ordering? It does handle ordering, just not the ordering you're asking for here. If you substituted USING ~<~ for ASC you'd find that the pattern_ops index could be used for that. >

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Andreas Joseph Krogh
On Thursday 09 August 2007 22:38:46 Andreas Joseph Krogh wrote: > On Thursday 09 August 2007 22:00:54 Gregory Stark wrote: > > "Andreas Joseph Krogh" <[EMAIL PROTECTED]> writes: > > > I create an index: > > > CREATE INDEX person_lowerfullname_idx ON > > > person((lower(COALESCE(firstname, '')) || l

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Andreas Joseph Krogh
On Thursday 09 August 2007 22:57:35 Rodrigo De León wrote: > On 8/9/07, Andreas Joseph Krogh <[EMAIL PROTECTED]> wrote: > > Ooops, just fugured that out. But - it still doesn't use the index if I > > remove the "varchar_pattern_ops". > > Huh? > > CREATE INDEX person_lowerfullname_idx > ON person >

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Rodrigo De León
On 8/9/07, Andreas Joseph Krogh <[EMAIL PROTECTED]> wrote: > Ooops, just fugured that out. But - it still doesn't use the index if I remove > the "varchar_pattern_ops". Huh? CREATE INDEX person_lowerfullname_idx ON person ((lower(COALESCE(firstname, '')) || lower(COALESCE(lastname, ''; EXPL

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Andreas Joseph Krogh
On Thursday 09 August 2007 22:00:54 Gregory Stark wrote: > "Andreas Joseph Krogh" <[EMAIL PROTECTED]> writes: > > I create an index: > > CREATE INDEX person_lowerfullname_idx ON > > person((lower(COALESCE(firstname, '')) || lower(COALESCE(lastname, ''))) > > varchar_pattern_ops); > > Why are you de

Re: [SQL] PG won't use index on ORDER BY

2007-08-09 Thread Gregory Stark
"Andreas Joseph Krogh" <[EMAIL PROTECTED]> writes: > I create an index: > CREATE INDEX person_lowerfullname_idx ON > person((lower(COALESCE(firstname, '')) || lower(COALESCE(lastname, ''))) > varchar_pattern_ops); Why are you declaring it using the varchar_pattern_ops? The default operator set

[SQL] PG won't use index on ORDER BY

2007-08-09 Thread Andreas Joseph Krogh
Hi all! I have problems getting PG to use an index when sorting. I have a simple table create table person( id serial primary key, firstname varchar, lastname varchar ); I create an index: CREATE INDEX person_lowerfullname_idx ON person((lower(COALESCE(firstname, '')) || lower(COALESCE(lastname

Re: [SQL] Indexing a field of type point

2007-08-09 Thread Tom Lane
David Cottingham <[EMAIL PROTECTED]> writes: > I have a table containing a field named location, of type point, i.e. a > position in two dimensions. The table has several million records in, and I > need to extract those records whose location value is contained within a > certain bounding box.

[SQL] Indexing a field of type point

2007-08-09 Thread David Cottingham
Hi, I realise this isn't strictly an SQL question, but I figured this list might be better suited than the general one. Please let me know if not. I have a table containing a field named location, of type point, i.e. a position in two dimensions. The table has several million records in, and