Reputation: 2437
Is it possible to create a table in SQL with the following requirements.
I have a table X with two cols, (primary key, value)
Every time, I add a new value to the above table, I create a new table with the name value.
So if there are 10 rows in table X, then we need to have 10 tables with names in the values field.
Let me try to explain the situation. I have a category A and I need to define it. The subsets of A can include {a1, a2, a3, ..... until infinity}
All the subsets have a different definition but are uniquely identified a property B.
B can be directly A, or a subset A with the definition holding true. I am not sure how to design it. I am using postgresql
So I am taking cues from a_horse_with_no_name and think that this can be a table structure.
Table A
<table border="1">
<td> primary_key </td>
<td> B1 </td>
<td> B2 </td>
<td> hstore - attribute </td>
</table>
Now what store should act like is similar to a tree.
hstore - attribute -> { a1 : {c1,c2,c3...}, a2 :{d1,d2,d3..}, .... }
C and D are structures here with multiple or single values. So if I am to use an hstore, is it possible to use something like a 2d array or something similar. It seems that it is possible from the following link.
http://www.postgresql.org/docs/9.0/static/hstore.html
I think this is certainly a better approach. Can you please check and comment. and so on..
Upvotes: 0
Views: 102
Reputation: 680
No, you can not do this. And should not.
edit: So, if you want subsets of a super set where all items are similar, you should create a column called 'parent_id' and reference the super set in that column.
Upvotes: 1
Reputation: 253
this practice is not nice to me. I think you should try another way solve your problem.
Upvotes: 0
Reputation: 951
Sounds like a bad idea, but yes, you can do that. Might need to get a bit creative to do it depending on what SQL you are using. You will most likely have to make a stored procedure, that creates a new table with it taking a name parameter. Then you can create a trigger on insert to call stored procedure, so every time a new value is inserted a table is created.
Upvotes: 0