I just forgot to add that and activity after that variable.

Details, details, details... :)

The query might be better as a join:

select distinct foo.id key, last_value(data.value) over ( partition by data.foo_id order by data.id ) value from foo, foo_data data where foo.id <> ? and foo.activity is true — and data.foo_id = foo.id and data.aktivity is true and data.key = 'name';

It's just natural derivation after associative arrays and key-value

That is great for programming. In the database world, it is generally considered the wrong approach, when the data is known. If data captured is unknown, it is likely the only choice.

Proper indexing is essential in that key-value-case.

That will work on small tables. Once it gets large, the index is of little help. Partitioned tables is one way out. In any case, EAVs are best avoided.

put everything to db, even code.

People do that, but it is error prone and confusing. Besides, queries can be stored natively in the database as a view or inside a stored procedure. That is what they are there for.


In reply to Re^7: How to interpolate sql-output by chacham
in thread How to interpolate sql-output by Seq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.