![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I'm trying to figure out a good way of representing any kind of discounts. I.E., you have a bunch of consumers with various attributes (age, student status, income, previous history of purchases, etc.), and you have producers who want to offer discounts based on any combination of these attributes. It seems to me that this must involve storing queries in a relation: e.g., you could have two columns: the amount of the discount, and the query that selects the people to apply this discount to. But what is the best way of storing a query in a particular relation? And what are the security implications of doing this----and how do you run these queries once you get them? Or, can anyone think of a better way of doing this? Thanks, Nick. |
#3
| |||
| |||
|
|
nchubrich wrote: I'm trying to figure out a good way of representing any kind of discounts. *I.E., you have a bunch of consumers with various attributes (age, student status, income, previous history of purchases, etc.), and you have producers who want to offer discounts based on any combination of these attributes. *It seems to me that this must involve storing queries in a relation: e.g., you could have two columns: the amount of the discount, and the query that selects the people to apply this discount to. But what is the best way of storing a query in a particular relation? And what are the security implications of doing this----and how do you run these queries once you get them? *Or, can anyone think of a better way of doing this? Thanks, Nick. Never store queries. *Have a table with a list of attributes and two link tables - one to link the attribute to the user and one to link the attribute to the discount. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstuck... (AT) attglobal (DOT) net ================== |
#4
| |||||
| |||||
|
|
I'm trying to figure out a good way of representing any kind of discounts. I.E., you have a bunch of consumers with various attributes (age, student status, income, previous history of purchases, etc.), and you have producers who want to offer discounts based on any combination of these attributes. |
|
It seems to me that this must involve storing queries in a relation: e.g., you could have two columns: the amount of the discount, and the query that selects the people to apply this discount to. |
|
But what is the best way of storing a query in a particular relation? |
|
And what are the security implications of doing this----and how do you run these queries once you get them? |
|
Or, can anyone think of a better way of doing this? |
#5
| |||
| |||
|
|
On Mar 9, 8:16 pm, Jerry Stuckle <jstuck... (AT) attglobal (DOT) net> wrote: nchubrich wrote: I'm trying to figure out a good way of representing any kind of discounts. I.E., you have a bunch of consumers with various attributes (age, student status, income, previous history of purchases, etc.), and you have producers who want to offer discounts based on any combination of these attributes. It seems to me that this must involve storing queries in a relation: e.g., you could have two columns: the amount of the discount, and the query that selects the people to apply this discount to. But what is the best way of storing a query in a particular relation? And what are the security implications of doing this----and how do you run these queries once you get them? Or, can anyone think of a better way of doing this? Thanks, Nick. Never store queries. Have a table with a list of attributes and two link tables - one to link the attribute to the user and one to link the attribute to the discount. How would you trigger discounts based on more general criteria in this scheme? E.G., I want to offer discounts to people with income under $35,000 and age over 65. Another producer may want to offer discounts over 60, under $20,000. Etc. |
#6
| |||
| |||
|
|
Another way I used in the past with a game I was working on needed to be much more complicated. This had hundreds of attributes for various things, and these attributes had to be adjustable, and often compounded (i.e. character strength went down if the character was hungry and/or had fought someone recently but up with armor). I ended up fetching all appropriate attribute id's for the character into an array in the application. Then at the appropriate places in the code, the application checked for the applicable entries. There was a lot of code involved (there needed to be), but I was dealing with a fairly closed set of attributes so little code needed to be changed when attributes changed. |
#7
| |||
| |||
|
|
On Wed, 10 Mar 2010 07:26:29 -0500, Jerry Stuckle wrote: Another way I used in the past with a game I was working on needed to be much more complicated. *This had hundreds of attributes for various things, and these attributes had to be adjustable, and often compounded (i.e. character strength went down if the character was hungry and/or had fought someone recently but up with armor). *I ended up fetching all appropriate attribute id's for the character into an array in the application. *Then at the appropriate places in the code, the application checked for the applicable entries. *There was a lot of code involved (there needed to be), but I was dealing with a fairly closed set of attributes so little code needed to be changed when attributes changed. Yup. The approach is fiendishly powerful, and about as economical as you can get without getting to the point of actually writing a language parser. There are whole general-purpose non-SQL query tools that build on exactly that kind of structure. -- Cunningham's First Law: Any sufficiently complex deterministic system will exhibit non-deterministic behaviour. |
#8
| |||
| |||
|
|
On Mar 10, 11:42 am, "Peter H. Coffin" <hell... (AT) ninehells (DOT) com> wrote: On Wed, 10 Mar 2010 07:26:29 -0500, Jerry Stuckle wrote: Another way I used in the past with a game I was working on needed to be much more complicated. This had hundreds of attributes for various things, and these attributes had to be adjustable, and often compounded (i.e. character strength went down if the character was hungry and/or had fought someone recently but up with armor). I ended up fetching all appropriate attribute id's for the character into an array in the application. Then at the appropriate places in the code, the application checked for the applicable entries. There was a lot of code involved (there needed to be), but I was dealing with a fairly closed set of attributes so little code needed to be changed when attributes changed. Yup. The approach is fiendishly powerful, and about as economical as you can get without getting to the point of actually writing a language parser. There are whole general-purpose non-SQL query tools that build on exactly that kind of structure. -- Cunningham's First Law: Any sufficiently complex deterministic system will exhibit non-deterministic behaviour. Thank you all for your help! Jerry--- I see how you could make attributes this way, but I am bothered by the way this turns a single number into a potentially infinite number of attributes. Although people don't normally grant discounts based on being age 31.415, I don't want to pre-conceive things. I was originally trying to develop a scheme something like what you showed me, and then I realized....there already \is a way of specifying things that satisfy arbitrary combinations of attributes, and more; and it's called SQL! I did not want to have to re-invent SQL itself; at the same time, I could not help feeling I was going against the grain by trying to use SQL in a way that it was seemingly not intended for. Hence my questions----and as you can see, I am fairly new to SQL. (By the way, I am using something called ClojureQL, which assembles queries using a Lisp-type notation. This may give me other options, especially of the kind that Erick mentioned, doing it in the application level.) Everyone seems to advise against storing queries. Does this mean not to use stored procedures, or is it specifically against storing queries in tables? What happens if one \does use queries in this way: security/inefficiency problems? And, if one uses stored procedures, how are these connected with particular discounts? I hope this isn't asking \too \many questions..... Nick. |
#9
| |||
| |||
|
|
Peter--- Any links to these query tools? |
#10
| |||
| |||
|
|
Even the source code files are database tables, with columns for the actual code, the sequence within the whole, and the date that the line was last updated. |
![]() |
| Thread Tools | |
| Display Modes | |
| |