SimpleDb - Can i make a SELECT IN statement - amazon-simpledb

Can I make a simple "select in" statement using simpleDb
Ex: SELECT * FROM Domain WHERE id in (1,2,3)
thanks.

Yes you can do it. You can use IN syntax like this.

Related

MyBatis Dynamic SQL join on subquery

I want to do something like this in MyBatis Dynamic SQL:
SELECT id FROM foo
JOIN (SELECT foo_id ...) bar ON foo.id = bar.foo_id
WHERE ...
However, the join() function only accepts SqlTable as an argument.
Is it possible to join on a subquery with MyBatis Dynamic SQL? If so, how do I do it?
MyBatis Dynamic SQL doesn't support these types of sub-queries right now. I'll think about adding it.
What's your database?
Do you really need to explicitly use JOIN like this?
Can't you do it just ike this?
SELECT id FROM foo , (select foo_id...) bar
WHERE foo.id = bar.foo_id

Rails + Postgres: How to select count of how many records are updated or inserted?

So I have an update statement:
UPDATE billing_infos set card_number = ''
FROM orders
WHERE billing_infos.order_id = orders.id ...);`
How would I find the count of how many records are updated by this statement?
I'm doing this in my console through ActiveRecord::Base.connection.execute() so it's just returning a <PG::Result:0x007f9c99ef0370> object.
Anyone know how I could do this using SQL or a Rails method?
p = ActiveRecord::Base.connection.execute(<query>)
p.cmd_status
This gives the command status. Something like
UPDATE 16
For more methods on PG::Result, refer here
While solution showed by Vimsha will definitely work, there is also another solution (assuming you use recent enough pg), which could be a bit nicer:
with u as (
update ... returning 1
)
select count(*) from u;
That's one query, and it's technically a select, so you run it as any other select.
As mentioned in a comment of another answer, the easiest way is to use the cmd_tuples attribute of the result
result = ActiveRecord::Base.connection.execute("insert into tbl select 'test' col")
puts result.cmd_tuples
result
1

coalesce in IQ is not working

I am using something like this:
select #x=coalesce(#x,'')+col1 from testdatatable
This works perfectly on SQL Server 2008 but for IQ it fails:
SELECT returns more than one row
We need more information on what your goal is here.
Is your select statement returning multiple rows? If so, IQ is attempting to set a single (varchar?) variable, #x, with many values...which isn't possible. It doesn't look like coalesce is your problem to me.
If are you trying get a single row back from testdatatable, and concatenate that single row's col1 with the #x, why not
select
#x = isnull(#x, '') + col1
from testdatatable
where (clause to get single row)

What is the :counter_sql option for?

What is the :counter_sql option for?
See here: rubyonrails association_basics. Find for :counter_sql in this page.
By :counter_sql you can specify your own counting sql like :couter_sql=>"select * from table where user=#{user}". If you so not specify it Rails automatically generates the proper SQL for counting.
And I quote
Specify a complete SQL statement to fetch the size of the association.
If :finder_sql is specified but not :counter_sql, :counter_sql will be
generated by replacing SELECT ... FROM with SELECT COUNT(*) FROM.
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

Left join in SubSonic Problem

I'm a beginner in SubSonic and I'm using version 2.1. I'd like to perform a left join in this query. The query looks like:
select ...
from tableA
left join tableB on tableA.Cola=tableB.Colb and tableB.Colc='some value'
I want to know how to perform the and tableB.Colc='some value' condition. I tried something like this:
new SubSonic.Select().From("tableA").LeftOuterJoin
("tableB","Colb","tableA","Cola").AndExpression("Colc").IsEqualTo("some value")
but the generated statement is not what I wanted.
This may not be exactly what you want , but the best way to do things like this in subsonic is with views, So create the select as a view and then use the view object in your code. In 3+ the linq makes it alot easier to accomplish what you are trying
It looks to me like the and part of your query should really be a where condition (you're trying to filter your results based on the value of tableB.Colc being equal to 'some value'). So what I think your sql query should look like is:
select ...
from tableA left join tableB on tableA.Cola=tableB.Colb
where tableB.Colc='some value' or tableB.Colc is null
If that is the case then in SubSonic you would do:
new SubSonic.Select()
.From("tableA").LeftOuterJoin ("tableB","Colb","tableA","Cola")
.Where("Colc").IsEqualTo("some value")
.Or("Colc").IsNull()

Resources