Tag: grammar

Non-obvious ALTER statements are gone

Decided to read PostgreSQL 8.4 Release notes before going to sleep and was pleasantly surprised. The fact of ALTER statements mess (which I described in my post) is now fixed:

Modify the ALTER TABLE syntax to allow all reasonable combinations for tables, indexes, sequences, and views (Tom)

This change allows the following new syntaxes:

  • ALTER SEQUENCE OWNER TO
  • ALTER VIEW ALTER COLUMN SET/DROP DEFAULT
  • ALTER VIEW OWNER TO
  • ALTER VIEW SET SCHEMA

There is no actual new functionality here, but formerly you had to say ALTER TABLE to do these things, which was confusing.

Cool! Way to go!

Windows path in PostgreSQL statements

note This article available in Russian.

There are not so many statements which take filesystem path as an argument. Of the top of my head:

  • CREATE TABLESPACE …
  • CREATE FUNCTION … (in case of dynamic loading C-Language functions)

So, the thing is that those arguments are just string constants, means there is no validation by lexer provided for them, what in it’s turn have different effects in different OSes. Not to say much:

warning Windows user! Replace your usual slashes (backslashes, actually) with the slashes like this one: ‘/’, in the file system path parameters!

WRONG:

CREATE TABLESPACE dbspace
  LOCATION 'C:\Program Files\PostgreSQL\8.3\data\dbs';
CREATE TABLESPACE dbspace
  LOCATION E'C:\Program Files\PostgreSQL\8.3\data\dbs';

RIGHT:

CREATE TABLESPACE dbspace
  LOCATION 'C:/Program Files/PostgreSQL/8.3/data/dbs';
CREATE TABLESPACE dbspace
  LOCATION 'C:\\Program Files\\PostgreSQL\\8.3\\data\\dbs';
-- but with warning! Do not ever do like this
CREATE TABLESPACE dbspace3
  LOCATION E'C:\\Program Files\\PostgreSQL\\8.3\\data\\dbs3'

P.S.: I do not like absolute paths. Why do we have $libdir magic for CREATE FUNCTION and do not have something similar for CREATE TABLESPACE?

That’s all folks!

Metamorphosis of gram.y

I often work with YACC (Bison) grammars, but still didn’t find comfortable editor for them. So I’m still using Notepad for this purpose. However, some time ago I found Perl script called linkify.pl as far as I remember, which produces HTML page based on the grammar and the list of non-terminal symbols. Edward Smirnov, colleague of mine, take this script and bring it to the completely new level.

What are the benefits of using such generated HTML page?

  • You can go exactly to whatever line number just adding #_<LINE>.

For example, if path to HTML grammar file is http://foo.com/MyGrammar.html, then http://foo.com/MyGrammar.html#_119 will bring you to the line number 119.

  • You can go exactly to the place where nonterminal symbol is defined.

All nonterminal symbols on this page are the links to theirs definitions indeed. Thus you may easily go down from the start symbol to the tokens using these links. One more benefit is that you may use “Back” browser button for one level up return.

  • Last but not least. Syntax highlighting: comments are grey, nonterminal symbols are close to red, the code and terminal symbols are navy.

Here you can find PostgreSQL LALR(1) grammar gram.y processed by this script.