Please see a example.

I have a table, name institutions, and exists a :name column.

Following is SQL generate by Sequel, please notice, there is a alias like 
this:

stock"."name" AS "stock_name"

```
SELECT "institutions"."id", "institutions"."name", 
"institutions"."number_of_holding", "instit
utions"."market_value", "institutions"."percent_of_shares_for_stock", 
"institutions"."percent_
of_shares_for_institution", "institutions"."quarterly_changes_percent", 
"institutions"."quarte
rly_changes", "institutions"."market_value_dollar_string", 
"institutions"."holding_cost", "ins
titutions"."date", "institutions"."created_at", "institutions"."stock_id", 
"institutions"."fir
m_id", "stock"."id" AS "stock_id_0", "stock"."name" AS "stock_name", 
"stock"."exchange_id", "s
tock"."percent_of_institutions", "stock"."ipo_price", "stock"."ipo_amount", 
"stock"."ipo_place
ment", "stock"."ipo_date", "stock"."ipo_average_price", 
"stock"."ipo_placement_number", "stock
"."next_earnings_date", "exchange"."id" AS "exchange_id_0", 
"exchange"."name" AS "exchange_nam
e", "firm"."id" AS "firm_id_0", "firm"."name" AS "firm_name", 
"firm"."display_name" FROM "inst
itutions" LEFT OUTER JOIN "stocks" AS "stock" ON ("stock"."id" = 
"institutions"."stock_id") LE
FT OUTER JOIN "exchanges" AS "exchange" ON ("exchange"."id" = 
"stock"."exchange_id") LEFT OUTE
R JOIN "firms" AS "firm" ON ("firm"."id" = "institutions"."firm_id") ORDER 
BY "stock"."name"
```

Then i remove :name column use sequel migration, then run same code, get 
following new SQL.

SELECT "institutions"."id", "institutions"."number_of_holding", 
"institutions"."market_value",
"institutions"."percent_of_shares_for_stock", 
"institutions"."percent_of_shares_for_instituti
on", "institutions"."quarterly_changes_percent", 
"institutions"."quarterly_changes", "institut
ions"."market_value_dollar_string", "institutions"."holding_cost", 
"institutions"."date", "ins
titutions"."created_at", "institutions"."stock_id", 
"institutions"."firm_id", "stock"."id" AS 
"stock_id_0", "stock"."name", "stock"."exchange_id", 
"stock"."percent_of_institutions", "stock
"."ipo_price", "stock"."ipo_amount", "stock"."ipo_placement", 
"stock"."ipo_date", "stock"."ipo
_average_price", "stock"."ipo_placement_number", 
"stock"."next_earnings_date", "exchange"."id"
AS "exchange_id_0", "exchange"."name" AS "exchange_name", "firm"."id" AS 
"firm_id_0", "firm".
"name" AS "firm_name", "firm"."display_name" FROM "institutions" LEFT OUTER 
JOIN "stocks" AS "
stock" ON ("stock"."id" = "institutions"."stock_id") LEFT OUTER JOIN 
"exchanges" AS "exchange"
ON ("exchange"."id" = "stock"."exchange_id") LEFT OUTER JOIN "firms" AS 
"firm" ON ("firm"."id
" = "institutions"."firm_id") ORDER BY "stock"."name"

The strange things is, why the first SQL generate stock"."name" AS 
"stock_name", and the second SQL not create alias like "AS "stock_name" ?

Following is service file which run will generate above SQL triggered by 
minitest spec, i can always reproduce it when running test.

https://github.com/zw963/marketbet_crawler/blob/master/app/services/retrieve_institutions.rb

Anyway, this is not a issue, add a alias not change anything, just for 
report, thank you.








-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/9ba4b507-c5ba-4158-8224-13fe6d99a811n%40googlegroups.com.

Reply via email to