Friday, 2011-04-01 Posted in [Postgresql-News][Pwn]
In today’s fast development cycles and with the available, rapidly changing technologies there is less time for the rational planning of a new application. Since the database is usually the last in the development chain, programmers tend to avoid learning yet another programming language for relational databases. The PostgreSQL Project is aware of this problem.
To enable this feature, the new GUC natural_language must be changed from off to english:
test=#SET natural_language TO'english';
test=#SET client_min_messages TO'notice';
From now on queries can be formulated in the English language. If users find the concept handy, other languages are also possible. A error-free English or American spelling is currently a mandatory requirement.
Queries must no longer be formally written in SQL, the ending semicolon can be optionally replaced with a dot.
test=# return allrowsfromtable customer.
NOTICE: Translated natural query into: SELECT*FROM"customer";
test=# I need the first three lines fromtable customer, only columns id andname.
NOTICE: Translated natural query into: SELECT id, nameFROM"customer"LIMIT3;
test=# Please retrn allfromtable purchases, sorted bydate.
ERROR: syntax error ator near "all"ROW1: Please retrn allfrom...^
test=# Please return allfromtable purchases, sorted bydate.
NOTICE: Translated natural query into: SELECT*FROM"purchases"ORDERBYdate;
test=#Fetchallrowsfromtable purchases with today's date in the date column, ordered by primary key.
NOTICE: Translated natural query into: SELECT * FROM "purchases" WHERE "date" = NOW()::DATE ORDER BY "id";
test=# Return "name" from the customer table where the value starts with an 'a'.
NOTICE: Translated natural query into: SELECT "name" FROM "customer" WHERE "name" ~ '^a';
Tables can be described with words:
test=# Need a tablefor user_data, which has a surrogate key, a timestamp, and a username andpasswordcolumn, bothtext.
NOTICE: Choosing "id"for surrogate keycolumn.
NOTICE: Choosing "inserted_at"fortimestampcolumn.
NOTICE: Translated natural query into: CREATETABLE"user_data" ("id"SERIALPRIMARYKEY, "inserted_at"TIMESTAMPWITH TIME ZONENOTNULLDEFAULT NOW(), "username"TEXT, "password"TEXT);
More complex tables should be created in the traditional way, to not confuse the language parser.