I recently evaluated this module in the context of pre-flighting some SQL that creates schema, and discovered that statement nodes with types like CreateStmt, CreateSeqStmt, etc are not adorned with accessors for the various elements of those statements. However, if I look into the objects' internal state, I can see that it's all there:
To demonstrate, here's a script called schema-parse.py that prints all the variables (private and public) of the first three statements in my schema file:
#!/usr/bin/python
from pprint import pprint, pformat
import psqlparse
fh = open('my-best-schema.sql', 'r')
sql = fh.read()
fh.close()
p = psqlparse.parser.parse(sql)
for i in range(0,3):
print pformat(vars(p[i])).replace(" ", " ")
print
$ python schema-parse.py
{'_obj': {u'sequence': {u'RangeVar': {u'inhOpt': 2,
u'location': 799,
u'relname': u'resource_id_seq',
u'relpersistence': u'p'}}},
'from_clause': None,
'target_list': None,
'type': u'CreateSeqStmt',
'where_clause': None,
'with_clause': None}
{'_obj': {u'oncommit': 0,
u'relation': {u'RangeVar': {u'inhOpt': 2,
u'location': 971,
u'relname': u'named_lock',
u'relpersistence': u'p'}},
u'tableElts': [{u'ColumnDef': {u'colname': u'lock_name',
u'constraints': [{u'Constraint': {u'contype': 4,
u'location': 1011}}],
u'is_local': True,
u'location': 988,
u'typeName': {u'TypeName': {u'location': 998,
u'names': [{u'String': {u'str': u'pg_catalog'}},
{u'String': {u'str': u'varchar'}}],
u'typemod': -1,
u'typmods': [{u'A_Const': {u'location': 1006,
u'val': {u'Integer': {u'ival': 255}}}}]}}}}]},
'from_clause': None,
'target_list': None,
'type': u'CreateStmt',
'where_clause': None,
'with_clause': None}
{'_obj': {u'sequence': {u'RangeVar': {u'inhOpt': 2,
u'location': 1108,
u'relname': u'job_seq',
u'relpersistence': u'p'}}},
'from_clause': None,
'target_list': None,
'type': u'CreateSeqStmt',
'where_clause': None,
'with_clause': None}
This is a feature request for plumbing the elements of 'create' statements up into the public variables provided by psqlparse