diesel
diesel

Reputation:

How do I return a date value in postgres sql?

For example:

year
-----
1999
2001
2004
2006

How do i return years that are greater than 2000?

Year is stored as date format.

Upvotes: 0

Views: 1423

Answers (1)

OMG Ponies
OMG Ponies

Reputation: 332541

Using PostgreSQL specific DATE_PART:

SELECT DATE_PART('year', t.date_column)
  FROM YOUR_TABLE t
 WHERE t.date_column > DATE '2000-01-01'

Using EXTRACT (ANSI):

SELECT EXTRACT(YEAR FROM t.date_column)
  FROM YOUR_TABLE t
 WHERE t.date_column > DATE '2000-01-01'

You could use the function in the WHERE clause to filter out the years/etc, but doing so renders an index on the column useless.

Upvotes: 3

Related Questions