MattF wrote:
hsn wrote:

best way for programing db apps in pgsql is to use stored procedures. They runs faster than
sending multiple queries to db, you can easily handle cases like this in stored procedures.

CREATE OR REPLACE FUNCTION bb_login(user_id text, ident text, logged timestamp) returns void as '
language 'plpgsql';

That one is way over my head. :D Where/how would that code be placed to utilise it?

place definitions of stored procedures into SQL statements used during install for creating tables, indexes, etc.
They can be called like other functions from SQL statements. Instead of coding INSERT into ... call procedure
using SELECT bb_login(arg1,arg2,arg3) MySQL5 supports stored procedure too, but syntax is bit different.

best way for programing db apps in pgsql is to use stored procedures. They runs faster than
sending multiple queries to db, you can easily handle cases like this in stored procedures.

CREATE OR REPLACE FUNCTION bb_login(user_id text, ident text, logged timestamp) returns void as '
DECLARE
rows integer;
BEGIN

UPDATE online SET logged=current_timestamp WHERE user=user_id;

GET DIAGNOSTICS rows = ROW_COUNT;

IF rows = 0 THEN
  INSERT INTO online (user_id, ident, logged) VALUES(user_id,ident,logged);
END IF;
END;
'
language 'plpgsql';