Re: ask: select right(column) ???

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: ask: select right(column) ???
Дата
Msg-id 20090216114455.GT32672@frubble.xen.chris-lamb.co.uk
обсуждение исходный текст
Ответ на ask: select right(column) ???  (hendra kusuma <penguinroad@gmail.com>)
Список pgsql-general
On Mon, Feb 16, 2009 at 03:21:20PM +0700, hendra kusuma wrote:
>  select right(column, number_of_character) from table
[..]
> honestly I have no idea that such simple feature doesn't exist in postgresql
> or am I wrong? since I look at SQL Key Words table and it's written as
> reserved

AFAIK, it's reserved because "right" is used in outer join syntax; i.e.
table RIGHT OUTER JOIN table, and not because of the function name.

If you want this in Postgres, you could always do:

  CREATE FUNCTION right(TEXT,INTEGER) RETURNS TEXT
    LANGUAGE sql IMMUTABLE STRICT AS $$
      SELECT substring($1 FROM char_length($1)-$2+1) $$;

Using "right" to extract the right most characters from a string sounds
very much like BASIC to me but may have moved to other languages now.
Humm, lets have a look; BASIC has Right$(), Pascal has RightStr(), MySql
has Right(), MS Sql Server has Right().  The other languages I chose to
look at (C, C++, Java, PHP, Lua, Ruby, Javascript) all naively expose a
substring function, like PG and Oracle, and leave anything like Right()
up to the user.

--
  Sam  http://samason.me.uk/

В списке pgsql-general по дате отправления:

Предыдущее
От: Sam Mason
Дата:
Сообщение: Re: left outer join without rows from "left" table
Следующее
От: Lennin Caro
Дата:
Сообщение: Re: ask: select right(column) ???