pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedPolymorphic?
3+ messages / 2 participants
[nested] [flat]
* Polymorphic?
@ 2003-02-25 15:09 Itai Zukerman <zukerman@math-hat.com>
0 siblings, 1 reply; 3+ messages in thread
From: Itai Zukerman @ 2003-02-25 15:09 UTC (permalink / raw)
To: pgsql-sql
I'd like to define a C function that takes two arguments of type
"array of <fixed-length type>" and returns an INT4. The function
would make use of the <, <=, =, >=, > operators on the base type. Any
examples of or documentation on how to:
1. Extract information about the underlying type from the arrays, in
particular the size of the type?
2. Apply an operator from within C?
--
Itai Zukerman <http://www.math-hat.com/~zukerman/;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Polymorphic?
@ 2003-02-25 16:20 Tom Lane <tgl@sss.pgh.pa.us>
parent: Itai Zukerman <zukerman@math-hat.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2003-02-25 16:20 UTC (permalink / raw)
To: Itai Zukerman <zukerman@math-hat.com>; +Cc: pgsql-sql
Itai Zukerman <zukerman@math-hat.com> writes:
> I'd like to define a C function that takes two arguments of type
> "array of <fixed-length type>" and returns an INT4. The function
> would make use of the <, <=, =, >=, > operators on the base type. Any
> examples of or documentation on how to:
> 1. Extract information about the underlying type from the arrays, in
> particular the size of the type?
> 2. Apply an operator from within C?
contrib/array might be a useful example of array manipulation. As for
the other stuff, do you actually want to invoke those operators
specifically, or are you looking for sorting? In any case you might
prefer to use any_ordering_op, SelectSortFunction and ApplySortFunction
rather than nailing down your own assumptions about what to compare
with.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Polymorphic?
@ 2003-02-26 03:40 Itai Zukerman <zukerman@math-hat.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: Itai Zukerman @ 2003-02-26 03:40 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-sql
>> 1. Extract information about the underlying type from the arrays, in
>> particular the size of the type?
>> 2. Apply an operator from within C?
>
> contrib/array might be a useful example of array manipulation. As for
> the other stuff, do you actually want to invoke those operators
> specifically, or are you looking for sorting? In any case you might
> prefer to use any_ordering_op, SelectSortFunction and ApplySortFunction
> rather than nailing down your own assumptions about what to compare
> with.
I think ApplySortFunction is exactly what I wanted.
I'm not sure when I'm going to get to it, but what I'd like to do is:
given an existing order relation on a type, extend it to an order on
arrays of that type. I've done it for INT4[], and it looks like the
general case is possible, just a question of figuring out which pegs
go in which slots. So far PostgreSQL's been a pleasure to work with;
kudos!
CREATE FUNCTION arr_int4_lt(int4[], int4[]) RETURNS boolean
AS 'arr_ops', 'generic_lt'
LANGUAGE 'C' STRICT;
CREATE FUNCTION arr_foo_lt(foo, foo) RETURNS boolean
AS 'arr_ops', 'generic_lt'
LANGUAGE 'C' STRICT;
etc.
--
Itai Zukerman <http://www.math-hat.com/~zukerman/;
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-02-26 03:40 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-25 15:09 Polymorphic? Itai Zukerman <zukerman@math-hat.com>
2003-02-25 16:20 ` Tom Lane <tgl@sss.pgh.pa.us>
2003-02-26 03:40 ` Itai Zukerman <zukerman@math-hat.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox