Re: PostgreSQL in Comparison to mySQL

Поиск
Список
Период
Сортировка
От Chris Smith
Тема Re: PostgreSQL in Comparison to mySQL
Дата
Msg-id 01051509082100.00749@area51.cybersydney.com.au
обсуждение исходный текст
Ответ на PostgreSQL in Comparison to mySQL  ("Jason" <jason@op480.com>)
Список pgsql-general
Hey,

> Can joined selects in pg be accomplished the same way as in mySQL?
> ie- "select person_name, person_age from names, ages where names.id=4 and
> names.id=ages.person_id"
> If not, what would be the syntax to perform such a query?

That should work be fine. (Pretty standard SQL I think).

> Also, I'm still a little unclear on how one utilizez the serial feature:
> In examples it seems like a serial type is not actually a column, but a
> sequence with a special name. I'm going to assume the following:
> Say I create a serial column called id on a table named people... how would
> I reference that in selects, updates, inserts, etc?

The same way as with mysql, its standard SQL.
SELECT foo1, foo2 from bar where id = 'number';

> It appears from
> examples that I would do:
>  "INSERT INTO people ('people_id_seq', 'name') VALUES
> (nextval('people_id_seq', 'name');"

No, it would still be INSERT INTO people ('people_id','name') VALUES
(nextval('people_id_seq'),'name');

You don't have to say the full sequence name, just the column name you wish
to access. But.. you don't explicitly need the nextval(..), there are
advantages to using it, such as if you need to insert this value into another
table somewhere else. You cans till write the query as

INSERT INTO people(name) VALUES ('name');

& postgresql will automatically add one to the sequence, and update that info
in the table.

> In mySQL you don't have to explicitly define the vaule for the
> auto_increment column, it will automatically select the next value upon
> insert.
> However, from what I gathered you DO have to explicitly define the nextval
> for a serial column type. Is this true? If so, does the query above look
> accurate?

No, you don't have to.

> Thanks for the info to help me make the migration to a real RDBMS.

Hope it makes some sense :)

--

     Chris Smith
http://www.squiz.net

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

Предыдущее
От: GH
Дата:
Сообщение: Re: PostgreSQL in Comparison to mySQL
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Trigger only firing once