[GENERAL] Auto Adjust Age

2011-04-06 Thread Carlos Mennens
I've only been using PostgreSQL since Oct 2010 and it's my first experience with SQL or any ORDBMS. I've searched on the web and been creating my own database users, databases, tables from scratch which has been interesting to say the least but now I would like to know if this is possible in SQL or

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Jerry Sievers
Carlos Mennens writes: > CREATE TABLE users > ( >id integer PRIMARY KEY UNIQUE NOT NULL, --ID >fname character varying(40) NOT NULL, --First name >lname character varying(40) NOT NULL, --Last name >email character varying NOT NULL, --email address >office integer NOT NULL, --O

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Rob Sargent
On 04/06/2011 08:53 AM, Carlos Mennens wrote: I've only been using PostgreSQL since Oct 2010 and it's my first experience with SQL or any ORDBMS. I've searched on the web and been creating my own database users, databases, tables from scratch which has been interesting to say the least but now

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Rob Sargent
On 04/06/2011 08:53 AM, Carlos Mennens wrote: I've only been using PostgreSQL since Oct 2010 and it's my first experience with SQL or any ORDBMS. I've searched on the web and been creating my own database users, databases, tables from scratch which has been interesting to say the least but now

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Andrew Sullivan
On Wed, Apr 06, 2011 at 10:53:49AM -0400, Carlos Mennens wrote: > online that shows me how to do so. I've created a table called 'users' > and I have it configured as follows: > > CREATE TABLE users > ( >id integer PRIMARY KEY UNIQUE NOT NULL, --ID >fname character varying(40) NOT NULL, --

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread JC de Villa
On Wed, Apr 6, 2011 at 11:15 PM, Jerry Sievers wrote: > Carlos Mennens writes: > >> CREATE TABLE users >> ( >>    id integer PRIMARY KEY UNIQUE NOT NULL, --ID >>    fname character varying(40) NOT NULL, --First name >>    lname character varying(40) NOT NULL, --Last name >>    email character var

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Karsten Hilbert
On Wed, Apr 06, 2011 at 11:15:31AM -0400, Jerry Sievers wrote: > I'd suggest not storing age but instead wrapping with a view that calls > date_trunc('year', now() - dob). Or put that in the query: SELECT ..., date_trunc('year', now() - dob) as age FROM users ; Karsten -

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Carlos Mennens
On Wed, Apr 6, 2011 at 11:20 AM, Andrew Sullivan wrote: > Why do you have the age stored at all?  When you SELECT from the table > and want someone's age, just do > >    SELECT [. . .], extract('years' from age(CURRENT_TIMESTAMP,dob)) as age >           . . . FROM users . . . > > By and large, it'

Re: [GENERAL] Auto Adjust Age

2011-04-06 Thread Carlos Mennens
On Wed, Apr 6, 2011 at 11:24 AM, JC de Villa wrote: > Theres also the age() function > > SELECT age(dob); > > Should give you > >           age > - >  31 years 5 mons 17 days > > If you want to be really exact about it. :) That worked awesome too! ide=# SELECT age(dob

Re: [GENERAL] Auto Adjust Age

2011-04-20 Thread Jasen Betts
On 2011-04-06, Carlos Mennens wrote: > I've only been using PostgreSQL since Oct 2010 and it's my first > experience with SQL or any ORDBMS. I've searched on the web and been > creating my own database users, databases, tables from scratch which > has been interesting to say the least but now I wo

Re: [GENERAL] Auto Adjust Age

2011-04-20 Thread Jasen Betts
On 2011-04-06, Jerry Sievers wrote: > Carlos Mennens writes: > >> CREATE TABLE users >> ( >>id integer PRIMARY KEY UNIQUE NOT NULL, --ID >>fname character varying(40) NOT NULL, --First name >>lname character varying(40) NOT NULL, --Last name >>email character varying NOT NULL, --e

Re: [GENERAL] Auto Adjust Age

2011-04-20 Thread Bill Moran
In response to Jasen Betts : > On 2011-04-06, Jerry Sievers wrote: > > Carlos Mennens writes: > > > >> CREATE TABLE users > >> ( > >>id integer PRIMARY KEY UNIQUE NOT NULL, --ID > >>fname character varying(40) NOT NULL, --First name > >>lname character varying(40) NOT NULL, --Last na