Skip site navigation (1) Skip section navigation (2)

Re: HOWTO? if it exists, increment it, else, insert it

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: HOWTO? if it exists, increment it, else, insert it
Date: 2007-01-25 17:25:07
Message-ID: 20070125172507.GA4755@a-kretschmer.de (view raw or flat)
Thread:
Lists: pgsql-novice
am  Thu, dem 25.01.2007, um  9:06:25 -0800 mailte Brian Neu folgendes:
> I can't seem to get CASE to work for me here and every example that I see is
> using CASE in a completely different way.
> 
> have a table:
> 
>     day(default CURRENT_DATE),   user,   count_of_a,    count_of_b
> 
> index is ("day", user)
> 
> 
> What is the best postgres way to handle updating this table?
> 
> I basically need to say,
> 
>     if (day,user) exists, then increment count A
>     else insert day, user, and count_a = 1.
> 

Take a look at:
http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

In response to

pgsql-novice by date

Next:From: Oisin GlynnDate: 2007-01-25 18:28:43
Subject: Re: Windows 2K Installation difficulties...
Previous:From: Brian NeuDate: 2007-01-25 17:06:25
Subject: HOWTO? if it exists, increment it, else, insert it

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group