Posts Tagged ‘table’

Conditional INSERT in SQL

Posted: 23rd October 2013 by Tim in SQL
Tags: , , , , , ,

Sometimes you want to run an INSERT statement in SQL only if some condition is met. There are a few methods available to do this, but not all of them are supported by all database systems. One method which is supported on all systems the use of a SELECT statement to return the row values, […]

Spanning columns in LaTeX tables

Posted: 27th November 2011 by Tim in LaTeX
Tags: , , , , , , ,

Tables are a fairly important part of LaTeX. Often you will want data to span multiple columns of the table, similar to colspan in HTML. In LaTeX it’s pretty easy too, using the \multicolumn{<cols>}{<format>}{<cell_text>} command, where <cols> is the number of columns to span and <format> is the cell format (l, c or r for […]

In LaTeX, by default, tables are numbered Table 1, Table 2, Table 3 an so on (or Table 1.1, Table 1.2, Table 2.1, etc if you’re using chapters). Sometimes you may want to change the way these are numbered. The solution is very similar to changing list numbering styles using different keywords. Like enumeration lists, […]

If you’ve written up a LaTeX document and find that some of the figures, tables, algorithms, etc. are being referenced wrong (such as Figure 2.4 being referenced as figure 6), chances are you’ve put your caption and \label tags in the wrong order. LaTeX needs \label to be after \caption, or for \label to be […]

DESCRIBE table in PostgreSQL

Posted: 20th January 2010 by Tim in PostgreSQL
Tags: , , , , ,

MySQL has a nice way to get the details of a table structure through the DESCRIBE command. PostgreSQL can also do this for you with \d table_name. For example (sorry about the poor layout): tim=# \d test_table Table “public.test_table” Column | Type | Modifiers ———+—————————–+——————- test_id | integer | not null default nextval(‘test_table_test_id_seq’::regclass) name | […]

Database systems such as MySQL allow you to specify a column as being auto incrementing. PostgreSQL, on the other hand, does things differently. Fields are incremented using sequences; external counters which are incremented manually. To use this requires setting up the sequence with a unique name and telling PostgreSQL to grab and increment the sequence […]

There are times when you want to explicitly set or reset the counter value on a SERIAL (auto incrementing) field or on a SEQUENCE. This may be done using a SELECT SETVAL(…) command. If you’re using a SERIAL field, PostgreSQL will actually create a SEQUENCE for you, which increments every time you insert a row. […]

Rotating a Page in LaTeX

Posted: 25th October 2009 by Tim in LaTeX
Tags: , , , , , , ,

Quite often you want to add a table or figure to a document which needs to be on a landscape page. You can use the pdflscape package to rotate single (or multiple) pages. Note that this works with latex as well as pdflatex. For example: \usepackage{pdflscape} … \begin{landscape} \begin{figure} \centering \includegraphics{my_figure} \label{fig:my_figure} \caption{My Figure} \end{figure} […]

Highlighting Table Rows in LaTeX

Posted: 6th September 2009 by Tim in LaTeX
Tags: , , , , , , , , ,

Ever want to highlight table rows in a LaTeX document? Unlike most LaTeX formatting, this one’s pretty simple. First, you need to \includepackage[table]{xcolor} at the top of the LaTeX document. (You will probably need to download the package (sudo apt-get install latex-xcolor on ubuntu). Next, simply add \rowcolor{color} before the table row. Colors include red, […]

MySQL Foreign Keys

Posted: 23rd July 2009 by Tim in MySQL
Tags: , , , ,

Foreign keys are a good way to ensure consistency between tables, by ensuring that the value in one table column exists in another table. For example, you might have a person table which contains person_id, first_name and surname. You may then have another table, person_ages, which contains person_id and date_of_birth. You would add a foreign […]

LaTeX Tables

Posted: 18th July 2009 by Tim in LaTeX
Tags: , , ,

Creating tables in LaTeX is one of the more complicated tasks in simple document writing. This tutorial will cover the basics of creating LaTeX tables, including adding captions, adding the table to the List of Tables as well as referencing the table in other parts of the document. LaTeX is good in the way it […]