The difficulty is that PG sub queries may return but a single column,
so the second SELECT * is invalid syntax.  Would this be valid SEQUEL?

order =
[:currency_code_base, :currency_code_quote, :effective_from.desc]

subquery = DB[:currency_exchange_rates___xchg2].select(:id).

  filter(:xchg1__currency_code_base=>:xchg2__currency_code_base).
  filter(:xchg1__currency_code_quote=>:xchg2__currency_code_quote).
  order(*order).
  limit(1)
DB[:currency_exchange_rates___xchg1].
  filter(:id=>subquery).
  order(*order)

and would it return

SELECT * FROM "currency_exchange_rates" AS "xchg1"
WHERE ("id" IN (

  SELECT id FROM "currency_exchange_rates" AS "xchg2"

  WHERE (("xchg1"."currency_code_base" = "xchg2"."currency_code_base")
AND
        ("xchg1"."currency_code_quote" =
"xchg2"."currency_code_quote"))
  ORDER BY "currency_code_base", "currency_code_quote",
"effective_from" DESC
  LIMIT 1))
ORDER BY "currency_code_base", "currency_code_quote", "effective_from"
DESC

which seems to work.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to