Обсуждение: Question on confusing behavior

Поиск
Список
Период
Сортировка

Question on confusing behavior

От
Steve Wolfe
Дата:
   Today, I told someone the syntax for "count" without thinking, and
got it wrong - and in so doing, I found some interesting behavior.


select count('table.fieldname');

works.  however...

select count('table.fieldname') where table.fieldname='something';

not only barfs, it kills your connection to the back-end.  Then...

select count(table.fieldname) where table.fieldname='something';


works fine.

  So, if the field name to count is enclosed in ticks, it works if there
is no where clause, but not if there is a where clause.

  Now I'm not an expert at SQL, so I realize that it could be because I
used totally illegal syntax.  But, then I'd think that postgres would
barf consistantly.  Anyone care to enlighten me as to what's going on?

steve

Re: [GENERAL] Question on confusing behavior

От
Bruce Momjian
Дата:
>    Today, I told someone the syntax for "count" without thinking, and
> got it wrong - and in so doing, I found some interesting behavior.
>
>
> select count('table.fieldname');
>
> works.  however...
>
> select count('table.fieldname') where table.fieldname='something';

Using the table.field in single-quotes makes it a string, and that is a
strange query.

Legally, you can do:

    select count(*) where table.fieldname='something';
    select count(table.fieldname) where table.fieldname='something';

However, I see your point, and will add it to the TODO list:

    * SELECT COUNT('asdf') FROM pg_class WHERE oid=12 crashes

--
  Bruce Momjian                        |  http://www.op.net/~candle
  maillist@candle.pha.pa.us            |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026