man page(1) manual page
Table of Contents


query - Query a QDDB database and print the results.


query Relation [-tcl [-norows]] [-sep `field separator'] -any Value | AttributeName Value [-any Value ...] [AttributeName Value ...] [-print AttributeName[:Width] ...]


query performs the given query on RelationDirectory and prints the result to stdout in a form suitable for reading by humans or interfacing with TCL.

The field separator is the character(s) that query uses to separate the row output of the attributes specified with the -print option and defaults to `:'. AttributeName is the full name of any attribute in the Schema for Relation_Name. Value is either a full word or white space separated list of words delimited by single quotes (depending on your shell). The :Width option of -print specifies the number of characters in AttributeName to print.


If the -tcl option is not specified, then query prints only attributes in rows matching the query. For example, suppose we have a database called Books that has the following QDDB Schema:

Use Cached Hashing
HashSize = 1000

Author *
Borrower (

and contains a small number of popular computer science texts. The query
$ query Books -sep `***' Author `donald knuth' -print Title ISBN might produce
Fundamental Algorithms***0-201-03809-9*** Seminumerical Algorithms***0-201-03822-6*** Sorting and Searching***0-201-03803-X*** and the query
$ query Books -sep `***' Author `donald knuth' -print Title:10 ISBN:12 would produce
Sorting an***0-201-03803-***
Human-readable output is useful when you want to quickly review the results of a QDDB query from the command line.


-tcl instructs query to format its output for use in TCL/TK scripts. -norows is used when the description of the selected row is not needed and is useful to prune the output for non-structured data.

Using the QDDB Schema given in the previous section, we might perform the query:
$ query Books -tcl -sep `***' Author `donald knuth' \ Title `fundamental' -print Title:10 ISBN:12 and see the output:
{ "Fundamenta***0-201-03809-***"
{ 1 359 0 1 }
{ Author,1 Title,1 ISBN,1 Description,1 Borrower.Name,1.1 Borrower.Phone,1.1 }
{ "Fundamenta***0-201-03809-***"
{ 1 359 0 1 }
{ Author,1 Title,1 ISBN,1 Description,1 Borrower.Name,2.1 Borrower.Phone,2.1 }

The output of query Books -tcl is a set of lists, each one having the format shown above. Each TCL list contains three elements, the result, the KeyList, and the row description.

The result element is usually used to display a list of items from which the user may choose. The contents of the KeyList element is used as arguments to qread(1) when the user selects from a given list. The row description is useful when the Schema is structured and contains expandable attributes. If the Schema is flat (not structured), then it is often useful to leave out the row description so that the number of bytes the TCL scripts must parse is reduced. Large Schemas produce particularly long row descriptions, especially when the attribute names are long. -norows instructs query not to print the row description.


query searches the QDDB Relation on a per-word basis. The result is the intersection of all records containing the words specified in the query. For example, $ query Books -any `arnold palmer' -print Title will search the QDDB relation named Books for all records that contain one or more fields with the word arnold and the word palmer, irrespective of the fields in which the words are actually contained. The query $ query Books Title `arnold palmer' -print Title Author will find all records containing the words arnold and palmer in the Title field and print out the Title field and Author of those records. You can mix any number of field specifications with any number of -any options.


qedit(1), qread(1)


query exits with an exit status of 1 if any error occurs and an exit status of 0 otherwise. This is sufficient to cause TK scripts using query to display an informative error box if an error occurs.

If the -print option is not used, then empty rows are printed.


Standard QDDB operations such as or and not, and search types such as regular expressions, string ranges, numeric ranges, and substrings, are not yet implemented in query.


A Guide to QDDB
Eric H. Herrin II and Raphael A. Finkel

Qddb User's Guide

An ASCII Database for Fast Queries of Relatively Stable Data Eric H. Herrin II and Raphael A. Finkel Computing Systems, Volume 4 Number 2
University of California Press, Berkeley CA

Schema and Tuple Trees: An Intuitive Structure for Representing Relational Data
Eric H. Herrin, II and Raphael A. Finkel Computing Systems, Volume 9, Number 2
MIT Press, Cambridge MA

Table of Contents