Skip site navigation (1) Skip section navigation (2)

Using regoper type with OPERATOR()

From: Tony Theodore <tony(dot)theodore(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Using regoper type with OPERATOR()
Date: 2011-10-05 05:42:18
Message-ID: CAJFv53puidmExYw9zsiSaKxLy3nJfksL21YNQ013UMqc=O=hSg@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hello,

Say I have a discount table that stores either percentages or dollar
amounts, and I'd like to save the operator to be used in a
calculation. I started with a text field and CASE statement, but then
found the operator types that seem more useful:

CREATE TABLE discounts(price float, disc float, disc_oper regoperator);
INSERT INTO discounts VALUES
		(100, .1, '*(float, float)'),
		(100, 10, '-(float, float)');

so I could use a query like:

SELECT price OPERATOR(disc_oper::regoper) disc AS disc_amount FROM discounts

This doesn't work however, and I'm not sure why. I think I'm missing
something simple since:

SELECT disc_oper::regoper FROM discounts;
  disc_oper
--------------
 pg_catalog.*
 pg_catalog.-
(2 rows)

and

SELECT 100 OPERATOR(pg_catalog.*) .1;

make me think I'm very close.

Any help appreciated.

Thanks,

Tony

Responses

pgsql-novice by date

Next:From: Gavin FlowerDate: 2011-10-06 01:43:30
Subject: Re: Using regoper type with OPERATOR()
Previous:From: Tom LaneDate: 2011-10-03 14:37:54
Subject: Re: how does LDFLAGS work?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group