dbTalk Databases Forums  

How to overload POSITION

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss How to overload POSITION in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Troels Arvin
 
Posts: n/a

Default How to overload POSITION - 11-16-2004 , 02:33 PM






Hello,

I'm working on a datatype which I call dnaseq. The basic stuff like
input/output functions, comparison operators, etc., work well.

I have overloaded the CHARACTER_LENGTH function without problems:

CREATE OR REPLACE FUNCTION character_length(dnaseq)
RETURNS integer
AS 'dnaseq','dnaseq_charlen'
LANGUAGE 'C' IMMUTABLE STRICT;

Now, I want to overload the POSITION(lftval IN rgtval) function, but how
do I do that? I've tried

CREATE OR REPLACE FUNCTION position(dnaseq,dnaseq)
RETURNS integer
AS 'dnaseq'
LANGUAGE 'C' IMMUTABLE STRICT;

But now I get:
ERROR: syntax error at or near "(" at character 36
LINE 1: CREATE OR REPLACE FUNCTION position(dnaseq,dnaseq)

I assume this is because the POSITION function uses "IN" to separate
arguments, in stead of a comma. Is there a way to overload it?

--
Greetings from Troels Arvin, Copenhagen, Denmark



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: How to overload POSITION - 11-16-2004 , 02:56 PM






Troels Arvin <troels (AT) arvin (DOT) dk> writes:
Quote:
I assume this is because the POSITION function uses "IN" to separate
arguments, in stead of a comma. Is there a way to overload it?
Double-quote "position" in the create function command --- it's a
keyword.

Be aware also of the argument order gotcha. Per gram.y:

Quote:
POSITION '(' position_list ')'
{
/* position(A in B) is converted to position(B, A) */
FuncCall *n = makeNode(FuncCall);
n->funcname = SystemFuncName("position");
n->args = $3;
n->agg_star = FALSE;
n->agg_distinct = FALSE;
$$ = (Node *)n;
}

Come to think of it, you'll also need to create your function in the
pg_catalog schema, because that's implied by SystemFuncName(). Which
means it won't get dumped by pg_dump. How wedded are you to being able
to say "IN"?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings



Reply With Quote
  #3  
Old   
Troels Arvin
 
Posts: n/a

Default Re: How to overload POSITION - 11-16-2004 , 03:12 PM



On Tue, 16 Nov 2004 15:56:00 -0500, Tom Lane wrote:

Quote:
[... cut advice ...]
Thanks.

Quote:
How wedded are you to being able to say "IN"?
It's only a would-be-nice-to-have.

My dnaseq data type exploits the fact that DNA sequences are made from a
very small alphabet (four characters), so strings can be compressed/packed
4:1 while still being directly usable. A POSITION(dnaseq IN dnaseq) would
mean that the dnaseq-values don't have to be converted to text before
being searched.

But I can live with my existing DNASEQ_POSITION(dnaseq,dnaseq) solution
(which works directly on the dnaseq packed strings).

(I will also try to create a specialized index for long strings, hopefully
using some substring array algorithmics - but that's another story.)

--
Greetings from Troels Arvin, Copenhagen, Denmark



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.