Re: Can quoting of table names be avoided?

2018-05-16 Thread Fatih Genç
Hi Jeremy,

Thank you very much for your reply, everything is ok now.


Jeremy Evans , 15 May 2018 Sal, 17:52 tarihinde
şunu yazdı:

> On Monday, May 14, 2018 at 10:57:14 PM UTC-7, Fatih Genç wrote:
>>
>> Hi,
>>
>> I'm tring to build a query with more than 1 table as fallows
>>
>> ds =
>> DB.select("r.year,r.prod,r.type,r.amnt,r.ccur,r.dcnt,r.dbcr,r.rcdt,r.stat
>> ,p.code as partner_code,p.desc as partner_desc,p.txid")
>> ds = ds.from("#{Rank.table_name.to_s} r","#{Partner.table_name.to_s}
>> p")
>> ds = ds.where(Sequel.lit('r.ptid = p.id'))
>>
>> ds.first returns an error "no such table: ranks r"
>>
>
>> What should I do to fix this?
>>
>
> Probably use Sequel's API to represent the objects:
>
> ds = DB.from(Sequel.as(Rank.table_name, :r), Sequel.as(Partner.table_name,
> :p)).
>   select{[r[:year], r[:prod], r[:type], r[:amnt], r[:ccur], r[:dcnt],
> r[:dbcr], r[:cdrt], r[:stat], p[:code].as(:partner_code),
> p[:desc].as(:partner_desc), p[:txid]]}.
>   where{{r[:ptid]=>p[:id]}}
>
> You could also just use Sequel.lit around each argument to select and from.
>
> Thanks,
> Jeremy
>
> --
> 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 sequel-talk+unsubscr...@googlegroups.com.
> To post to this group, send email to sequel-talk@googlegroups.com.
> Visit this group at https://groups.google.com/group/sequel-talk.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Fatih Genç

-BEGIN PGP PUBLIC KEY BLOCK-

mQINBFlsSrwBEADt1lDF9feJBGZIMr03JF26ajU+k84LI3rrTwMfXiCJGvjs+oH6
z7Wo80C9uMcr37XNinU6Bnt/7KwpJgDvljz1VLTpZBkLWpYkKddN0OO6xAv85Qbj
P4NS7I+EdW/ixXFB/61BFJ8MEyLzUm5qCdA26cO0ZutQSnIiGrt+A48J8kgVey0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5g/+JW1NZEHNb7VoT9uahDbKMOcv1L9UeY9alBAHvbMbtBywflgp
YUnx6Mz939f59tLd9321hr1eJtjsTfPvuCMbaq0LNgh4OrxldhxTGEAO0uYKsUmC
O3y/JKws3JVn8oM/1KAzco93+RGj420dd/x9XNpUbsBFUUTWCq7xx8HB6I2O9ms5
G/T1SHJszRSIivi1XQFgU4IuDY29R5XlNpqRpwAfnZQ9iszIXq9z2PbMiQRtuNp/
RK1mC+zNehaTFwZzhLaRGZl4qjANM8nu8sTHUTho2LBM0VE0KEd00TxchG34bssL
UF4z2lmpbLLHf8qwvA99NnNffqRMbHjIU/N0nDUuyu87A94MeiCu3WXKhbkZ6qM6
fKfCrfgRcnCxiOqqzqmgaWGBH9oKopJ+QYP4F8QbvtVxaEMQQgyLR8CShZXuWc7H
S9+O8HVYycMuKkxVbgwKFBOUkGG+ZUMN2fJjXnINzrSILLw7jj7xigINE64Ra2UF
5aXKZ1jI9B4CSswu0DX4KFe/3Zt50FSd7R2erp7BoOrirZAUd9/uAj6l51lhlIr1
I7sfZcx6JbFt1WgBlURcicmvZ9JzpqKCuDL6FbmvXLafI3Av1f7Vj7+6W2BwNsvq
1f0Dd7ErIGrs5tgSusHzb6lVDE9oxrheVTrPJ6Hr68NFKcDkA1CuyaPji9E=
=MNMk
-END PGP PUBLIC KEY BLOCK-

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to 

Re: Can quoting of table names be avoided?

2018-05-15 Thread Jeremy Evans
On Monday, May 14, 2018 at 10:57:14 PM UTC-7, Fatih Genç wrote:
>
> Hi,
>
> I'm tring to build a query with more than 1 table as fallows
>
> ds = 
> DB.select("r.year,r.prod,r.type,r.amnt,r.ccur,r.dcnt,r.dbcr,r.rcdt,r.stat 
> ,p.code as partner_code,p.desc as partner_desc,p.txid")
> ds = ds.from("#{Rank.table_name.to_s} r","#{Partner.table_name.to_s} 
> p")
> ds = ds.where(Sequel.lit('r.ptid = p.id'))
>
> ds.first returns an error "no such table: ranks r"
>

> What should I do to fix this?
>

Probably use Sequel's API to represent the objects:

ds = DB.from(Sequel.as(Rank.table_name, :r), Sequel.as(Partner.table_name, 
:p)).
  select{[r[:year], r[:prod], r[:type], r[:amnt], r[:ccur], r[:dcnt], 
r[:dbcr], r[:cdrt], r[:stat], p[:code].as(:partner_code), 
p[:desc].as(:partner_desc), p[:txid]]}.
  where{{r[:ptid]=>p[:id]}} 

You could also just use Sequel.lit around each argument to select and from.

Thanks,
Jeremy

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


Re: Can quoting of table names be avoided?

2018-05-14 Thread Fatih Genç
Hi,

I'm tring to build a query with more than 1 table as fallows

ds = 
DB.select("r.year,r.prod,r.type,r.amnt,r.ccur,r.dcnt,r.dbcr,r.rcdt,r.stat 
,p.code as partner_code,p.desc as partner_desc,p.txid")
ds = ds.from("#{Rank.table_name.to_s} r","#{Partner.table_name.to_s} p")
ds = ds.where(Sequel.lit('r.ptid = p.id'))

ds.first returns an error "no such table: ranks r"

What should I do to fix this?


On Monday, September 12, 2016 at 12:25:58 AM UTC+3, Jeremy Evans wrote:
>
> On Sunday, September 11, 2016 at 2:22:32 PM UTC-7, Will Koffel wrote:
>>
>> I have the following:
>>
>> (byebug) puts DB.from(:users).select("email").sql
>>
>> SELECT 'email' FROM "users"
>>
>> The problem is that the DB doesn't accept that SQL, because the table 
>> name is quoted.
>>
>> (byebug) DB[DB.from(:users).select("email").sql].each { |r| puts r }
>>
>> *** Sequel::DatabaseError Exception: PG::UndefinedTable: ERROR: 
>>  relation "users" does not exist
>>
>> The query works just fine manually if the table name is bare.
>>
>> The DB is RedShift.  I don't have a PG database hooked up to test with, 
>> but maybe this is a quirk of Redshift that the redshift adapter doesn't 
>> handle properly?
>>
>> I feel like I'm missing something obvious here.  Is there any way to get 
>> the table name not to be quoted?
>>
>  
> DB.quote_identifiers = false
>
> Thanks,
> Jeremy
>

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


Re: Can quoting of table names be avoided?

2016-09-12 Thread Matt Palmer
On Sun, Sep 11, 2016 at 10:02:11PM -0700, Jeremy Evans wrote:
> On Sunday, September 11, 2016 at 7:12:24 PM UTC-7, Matt Palmer wrote:
> >
> > On Sun, Sep 11, 2016 at 11:05:17AM -0700, Will Koffel wrote: 
> > > I have the following: 
> > > 
> > > (byebug) puts DB.from(:users).select("email").sql 
> > > 
> > > SELECT 'email' FROM "users" 
> > > 
> > > The problem is that the DB doesn't accept that SQL, because the table 
> > name 
> > > is quoted. 
> > > 
> > > (byebug) DB[DB.from(:users).select("email").sql].each { |r| puts r } 
> > > 
> > > *** Sequel::DatabaseError Exception: PG::UndefinedTable: ERROR: 
> >  relation 
> > > "users" does not exist 
> > > 
> > > The query works just fine manually if the table name is bare. 
> >
> > Does the query fail as expected when you quote the table name? 
> >
> > > The DB is RedShift.  I don't have a PG database hooked up to test with, 
> > but 
> > > maybe this is a quirk of Redshift that the redshift adapter doesn't 
> > handle 
> > > properly? 
> >
> > I'd say this is a quirk of redshift: 
> >
> > => create table users (id int); 
> > CREATE TABLE 
> > => select 'email' from "users"; 
> >  ?column? 
> >  -- 
> >  (0 rows) 
> >
> 
> Actually, it's not.  You are selecting a string expression (single quotes) 
> without an alias, so the ?column? is expected, and there are no rows 
> because you just created the table.

Sorry, I wasn't clear: that example was given on a PostgreSQL 9.4 server. 
It demonstrates that the query generated by Sequel (that I executed) is
valid syntax *for PostgreSQL*; thus, if the same query fails with `ERROR:
relation "users" does not exist` in redshift, then that is a
redshift-specific quirk.

- Matt

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


Re: Can quoting of table names be avoided?

2016-09-11 Thread Jeremy Evans
On Sunday, September 11, 2016 at 7:12:24 PM UTC-7, Matt Palmer wrote:
>
> On Sun, Sep 11, 2016 at 11:05:17AM -0700, Will Koffel wrote: 
> > I have the following: 
> > 
> > (byebug) puts DB.from(:users).select("email").sql 
> > 
> > SELECT 'email' FROM "users" 
> > 
> > The problem is that the DB doesn't accept that SQL, because the table 
> name 
> > is quoted. 
> > 
> > (byebug) DB[DB.from(:users).select("email").sql].each { |r| puts r } 
> > 
> > *** Sequel::DatabaseError Exception: PG::UndefinedTable: ERROR: 
>  relation 
> > "users" does not exist 
> > 
> > The query works just fine manually if the table name is bare. 
>
> Does the query fail as expected when you quote the table name? 
>
> > The DB is RedShift.  I don't have a PG database hooked up to test with, 
> but 
> > maybe this is a quirk of Redshift that the redshift adapter doesn't 
> handle 
> > properly? 
>
> I'd say this is a quirk of redshift: 
>
> => create table users (id int); 
> CREATE TABLE 
> => select 'email' from "users"; 
>  ?column? 
>  -- 
>  (0 rows) 
>

Actually, it's not.  You are selecting a string expression (single quotes) 
without an alias, so the ?column? is expected, and there are no rows 
because you just created the table.

Thanks,
Jeremy

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


Re: Can quoting of table names be avoided?

2016-09-11 Thread Matt Palmer
On Sun, Sep 11, 2016 at 11:05:17AM -0700, Will Koffel wrote:
> I have the following:
> 
> (byebug) puts DB.from(:users).select("email").sql
> 
> SELECT 'email' FROM "users"
> 
> The problem is that the DB doesn't accept that SQL, because the table name 
> is quoted.
> 
> (byebug) DB[DB.from(:users).select("email").sql].each { |r| puts r }
> 
> *** Sequel::DatabaseError Exception: PG::UndefinedTable: ERROR:  relation 
> "users" does not exist
> 
> The query works just fine manually if the table name is bare.

Does the query fail as expected when you quote the table name?

> The DB is RedShift.  I don't have a PG database hooked up to test with, but 
> maybe this is a quirk of Redshift that the redshift adapter doesn't handle 
> properly?

I'd say this is a quirk of redshift:

=> create table users (id int);
CREATE TABLE
=> select 'email' from "users";
 ?column?
 --
 (0 rows)

http://docs.aws.amazon.com/redshift/latest/dg/r_names.html suggests this
*should* be supported, at least in some way.  I'm a bit leery of the
sentence, "If you use a delimited identifier, you must use the double
quotation marks for every reference to that object.", which suggests that
you would need create the table as being named `"users"`, rather than just
`users`, if you wanted it to work with quotes later, but that might be an
imprecision in the phrasing, rather than what is literally meant.

- Matt

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.


Re: Can quoting of table names be avoided?

2016-09-11 Thread Jeremy Evans
On Sunday, September 11, 2016 at 2:22:32 PM UTC-7, Will Koffel wrote:
>
> I have the following:
>
> (byebug) puts DB.from(:users).select("email").sql
>
> SELECT 'email' FROM "users"
>
> The problem is that the DB doesn't accept that SQL, because the table name 
> is quoted.
>
> (byebug) DB[DB.from(:users).select("email").sql].each { |r| puts r }
>
> *** Sequel::DatabaseError Exception: PG::UndefinedTable: ERROR:  relation 
> "users" does not exist
>
> The query works just fine manually if the table name is bare.
>
> The DB is RedShift.  I don't have a PG database hooked up to test with, 
> but maybe this is a quirk of Redshift that the redshift adapter doesn't 
> handle properly?
>
> I feel like I'm missing something obvious here.  Is there any way to get 
> the table name not to be quoted?
>
 
DB.quote_identifiers = false

Thanks,
Jeremy

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.