Replace into equivalent for postgresql and then autoincrementing an int

Posted by Mohamed Ikal Al-Jabir on Stack Overflow See other posts from Stack Overflow or by Mohamed Ikal Al-Jabir
Published on 2010-06-16T22:23:10Z Indexed on 2010/12/22 2:54 UTC
Read the original article Hit count: 318

Filed under:
|
|
|

Okay no seriously, if a postgresql guru can help out I'm just getting started.

Basically what I want is a simple table like such:

CREATE TABLE schema.searches
(
  search_id serial NOT NULL,
  search_query character varying(255),
  search_count integer DEFAULT 1,
  CONSTRAINT pkey_search_id PRIMARY KEY (search_id)
)
WITH (
  OIDS=FALSE
);

I need something like REPLACE INTO for mysql. I don't know if I have to write my own procedure or something?

Basically:

  • check if the query already exists
  • if so, just add 1 to the count
  • it not, add it to the db

I can do this in my php code but I'd rather all that be done in postgres C engine

Thanks for helping

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql