Query a birth chart with SQL: 10 example queries

A birth chart is laid out like a table. The planets, the houses and the aspects each sit in a table of their own. MansionSQL lets you ask those tables questions in SQL. This guide reads ten questions through their real queries and the engine's real answers.

What is MansionSQL?

MansionSQL is an SQL language written for the birth chart. Once the chart is calculated, it opens as six main tables. planets holds the ten planets, chart every body and point the chart calculated, houses the twelve houses, aspects every aspect found, stars the fixed stars and lots the 38 Arabic lots. A query picks what it wants with SELECT, filters it with WHERE and counts it with GROUP BY.

A query runs in milliseconds on AstroMansion's own engine. Only SELECT is accepted, and every other command is refused before it reaches the engine, so a query cannot change any data. An answer holds at most 100 rows. A longer answer is never cut short, it is refused openly.

The language's keywords and column names are English, and so are the sign and planet names in an answer. The tables in this guide are written as the MansionSQL page shows them.

The example birth

Every example was calculated with the documentation's shared birth. The same birth is open to everyone in the MansionSQL page's trial, so you can run each query here yourself and see the same answer.

The documentation's shared example birth and the size of its chart.
Birth
London, 15 July 1990, 14:30
House system
Placidus
Bodies and points in the chart
55
Planets
10

The main placements

Where are the Sun, the Moon and the Ascendant?

SELECT name, sign, dms, house
FROM chart
WHERE name IN ('Sun', 'Moon',
               'Ascendant')
namesigndmshouse
SunCancer22°48′21″9
MoonAries24°8′6″6
AscendantScorpio1°58′5″1

The Sun is in Cancer in the 9th house, the Moon in Aries in the 6th, and the Ascendant at 1°58′ Scorpio. The Ascendant is not a planet but the eastern point of the horizon, so the query reads the chart table, which holds every body and point of the chart, rather than planets. The dms column writes the place within the sign in degrees, minutes and seconds.

Which planets are retrograde?

SELECT name, sign, dms
FROM planets
WHERE retrograde = 1
namesigndms
SaturnCapricorn21°57′32″
UranusCapricorn6°57′51″
NeptuneCapricorn12°55′10″
PlutoScorpio14°59′57″

In this birth Saturn, Uranus, Neptune and Pluto move backwards as seen from Earth. The outer planets stay retrograde for months every year, so charts with all four retrograde at once are common. The condition retrograde = 1 keeps only the planets that move backwards.

The tightest aspects

Which are the five tightest aspects between planets?

SELECT a, b, aspect, orb
FROM aspects
WHERE a IN (SELECT name FROM planets)
  AND b IN (SELECT name FROM planets)
ORDER BY orb
LIMIT 5
abaspectorb
SunJupiterConjunction0.243
MoonVenusSextile0.351
JupiterSaturnOpposition0.604
SunSaturnOpposition0.847
SunMoonSquare1.329

The aspects table holds both sides of each aspect (a and b), its name and its orb. The orb is how many degrees the aspect is away from exact. The smaller the orb, the tighter the aspect, and in a traditional reading the stronger it acts. The tightest aspect in this birth is the conjunction of the Sun and Jupiter, with an orb of 0.243 degrees, about 15 minutes of arc.

The two subqueries require both sides of the aspect to be planets. The table holds 199 aspects in this birth, and without the subqueries the lunar nodes, Lilith and the hypothetical planets come into the list too. A subquery must select a single column, and one that selects two is refused.

Elements and signs

How are the planets spread across the elements?

SELECT ELEMENT(sign) AS element,
       COUNT(*) AS planet_count
FROM planets
GROUP BY ELEMENT(sign)
ORDER BY planet_count DESC
elementplanet_count
earth4
water3
fire2
air1

ELEMENT gives a sign's element, and GROUP BY gathers the planets by it. Four planets are in earth signs (Mars in Taurus, and Saturn, Uranus and Neptune in Capricorn). Three are in water (the Sun and Jupiter in Cancer, Pluto in Scorpio), two in fire (the Moon in Aries, Mercury in Leo) and one in air (Venus in Gemini). Write the same query with MODALITY and you get the spread across cardinal, fixed and mutable signs.

Which signs hold more than one planet?

SELECT sign, COUNT(*) AS planet_count
FROM planets
GROUP BY sign
HAVING COUNT(*) >= 2
ORDER BY planet_count DESC
signplanet_count
Capricorn3
Cancer2

HAVING filters after the groups are formed. Here it keeps the signs that hold at least two planets. The three planets in Capricorn are Saturn, Uranus and Neptune, a generational signature found in the chart of everyone born in 1989 and 1990. Many astrologers call three or more planets in one sign a stellium. To change the threshold, write HAVING COUNT(*) >= 3.

A planet's strength in its sign

Which planets are in a strong or weak sign?

SELECT name, sign,
       DIGNITY(name, sign) AS dignity
FROM planets
WHERE DIGNITY(name, sign)
      <> 'peregrine'
namesigndignity
MarsTaurusdetriment
JupiterCancerexaltation
SaturnCapricorndomicile

In traditional astrology the sign a planet stands in gives it strength or weakness. This is called essential dignity. A planet in a sign it rules is in its domicile, and in the sign of its exaltation it is in exaltation. Opposite a sign it rules it is in detriment, and opposite its exaltation it is in fall.

In this birth Saturn is in Capricorn, a sign it rules, and Jupiter in Cancer, the sign of its exaltation. Mars is in Taurus, opposite Scorpio, which it rules, and so in detriment. The other planets are in none of these four states, and the engine writes them as peregrine.

DIGNITY reads the table of the seven classical planets. Uranus, Neptune and Pluto rule no sign in the tradition, so they always return peregrine. The minor dignities of triplicity, term and face are not reported, because they need a degree and the difference between day and night, which a sign alone does not give. In the tradition, peregrine means a planet with no dignity at all. Here it says that none of the four states applies.

Angles, houses and their rulers

Which signs are on the four angles?

SELECT number, sign, dms
FROM houses
WHERE number IN (1, 4, 7, 10)
numbersigndms
1Scorpio1°58′5″
4Aquarius13°2′56″
7Taurus1°58′5″
10Leo13°2′56″

In quadrant house systems such as Placidus, the cusps of the 1st, 4th, 7th and 10th houses are the chart's four angles. They are the Ascendant, the Imum Coeli (IC), the Descendant and the Midheaven (MC). Opposite angles fall in opposite signs at the same degree. With the Ascendant at 1°58′ Scorpio the Descendant is at 1°58′ Taurus, and with the MC at 13°2′ Leo the IC is at 13°2′ Aquarius. ANGULAR(house) says whether a house is angular, succedent or cadent.

Which house is each planet in, and who rules it?

SELECT p.name, p.house,
       h.sign AS cusp_sign,
       RULER(h.sign) AS cusp_ruler
FROM planets p
JOIN houses h ON p.house = h.number
namehousecusp_signcusp_ruler
Sun9CancerMoon
Moon6AriesMars
Mercury9CancerMoon
Venus8TaurusVenus
Mars7TaurusVenus
Jupiter9CancerMoon
Saturn3CapricornSaturn
Uranus3CapricornSaturn
Neptune3CapricornSaturn
Pluto1ScorpioMars

JOIN joins two tables over a shared value. Here each planet meets the row of the house it stands in. A house's cusp sign need not be the planet's own sign. Mercury is in Leo, but the 9th house begins in Cancer, so the ruler of Mercury's house is the Moon. Venus is in the 8th house, which begins in Taurus, so Venus stands in a house it rules itself.

RULER gives the traditional ruler only. Mars rules Scorpio, Saturn Aquarius and Jupiter Pisces. Pluto is in the 1st house, which begins in Scorpio, so the answer gives the traditional ruler Mars rather than the modern ruler Pluto.

Which houses are empty?

SELECT number, sign
FROM houses h
WHERE NOT EXISTS (
  SELECT 1 FROM planets p WHERE p.house = h.number
)
numbersign
2Scorpio
4Aquarius
5Pisces
10Leo
11Virgo
12Libra

NOT EXISTS is true when the subquery inside it finds no row. Here the subquery looks in each house for a planet standing there. When it finds none, the house counts as empty. Six houses hold no planet in this birth. A house without a planet is not an unimportant house. It is read through the ruler of its cusp sign, which is exactly what the RULER query above shows.

Looking for empty houses with the bodies column of the houses table gives another answer. That column counts not only the planets but all 55 bodies and points of the chart. Among them are the lunar nodes, Lilith, the hypothetical planets, some minor bodies and calculated points.

SELECT number, sign
FROM houses
WHERE bodies = 0
numbersign
4Aquarius

This query finds only the 4th house, because the other five houses hold no planet but do hold another body or point. Astrology usually counts a house as empty or occupied by its planets, which is why the page's question looks at the planets.

The Lots of Fortune and Spirit

Where are the Lots of Fortune and Spirit?

SELECT name, sign, dms, house
FROM lots
WHERE name IN ('Fortune', 'Spirit')
namesigndmshouse
FortuneLeo3°17′51″9
SpiritAquarius0°38′20″3

Most Arabic lots are found by moving on from the Ascendant by the arc between two bodies. In a day birth the Lot of Fortune is Ascendant + Moon − Sun, and the Lot of Spirit Ascendant + Sun − Moon. In a night birth the two formulas swap. The engine counts a birth as a night birth when the Sun is below the horizon.

The example birth is in the afternoon, with the Sun in the 9th house above the horizon, so it is a day chart. Add the arc from the Sun to the Moon to the Ascendant at 1°58′ Scorpio, and the Lot of Fortune falls at 3°17′ Leo. The lots table holds all 38 lots the engine calculates.

Astrological functions

These functions can be used anywhere in a query, in SELECT, WHERE, GROUP BY and ORDER BY. Each reads a table or does simple arithmetic, and none calculates the chart again.

  • ELEMENT(sign) gives the sign's element. The answers are fire, earth, air and water.
  • MODALITY(sign) says whether it is cardinal, fixed or mutable.
  • RULER(sign) gives the traditional ruler.
  • DIGNITY(body, sign) reads the essential dignity of the seven classical planets.
  • DECAN(longitude) says which ten-degree part of the sign a degree falls in, the first, second or third decan.
  • ANGULAR(house) says whether a house is angular, succedent or cadent.
  • ORB(a, b) gives the angle between two longitudes, never more than 180 degrees.

Aggregates such as COUNT, AVG, MIN, MAX and SUM work too, and so do CASE WHEN, LIKE, BETWEEN and EXISTS. The full list of the language is in the documentation.

On your own chart and in the API

The MansionSQL page has ten ready questions and a trial box. The trial on the example birth is free for everyone. To run a query on your own birth, tick My own birth and enter your birth details. This needs the Basic, Pro or Enterprise plan.

The same queries run in the API through POST /v1/query. There you can bring a second birth into a synastry query through the natal_b table, and set the sky of a moment beside the birth chart through the transits table. The answer comes as JSON, and you can also take it as CSV or as a table to read in a terminal. Developers find the details on the developers page.

Sources and calculation

Every table was calculated with the documentation's shared birth on AstroMansion's engine and written as the MansionSQL page shows it. The essential dignities and the formulas of the Arabic lots follow their definitions in the traditional sources.

Frequently Asked

Do I need to know SQL to use MansionSQL?

No. Clicking one of the ten ready questions on the MansionSQL page is enough, and its query fills the box and runs. To change a query, starting with SELECT, FROM and WHERE is enough. Since only SELECT runs, a query cannot damage any data.

Which house system does MansionSQL use?

Placidus is used when no house system is given, and the example birth in this guide was calculated with Placidus houses. In the API you can choose another house system through the birth's houses field.

How do I run MansionSQL on my own birth chart?

On the MansionSQL page, tick My own birth and enter your birth date, time and place. Querying your own birth is open on the Basic, Pro and Enterprise plans. The trial on the example birth is free for everyone.

More guides