postgresql-8.4

Select today's (since midnight) timestamps only

血红的双手。 提交于 2019-11-29 05:25:11
I have a server with PostgreSQL 8.4 which is being rebooted every night at 01:00 (don't ask) and need to get a list of connected users (i.e. their timestamps are u.login > u.logout ): SELECT u.login, u.id, u.first_name FROM pref_users u WHERE u.login > u.logout and u.login > now() - interval '24 hour' ORDER BY u.login; login | id | first_name ----------------------------+----------------+------------- 2012-03-14 09:27:33.41645 | OK171511218029 | Alice 2012-03-14 09:51:46.387244 | OK448670789462 | Bob 2012-03-14 09:52:36.738625 | OK5088512947 | Sergej But comparing u.login > now()-interval '24

How do I import modules or install extensions in Postgres 8.4?

天涯浪子 提交于 2019-11-28 15:28:18
I'm trying to import several modules that come bundled with 8.4.1 postgres, and all the commands to do so (such as contrib.import etc) do not work or cannot be found. Please help me. To install PostgreSQL contrib modules on Ubuntu or Kubuntu (or similar Linux distributions): Install the contrib package: sudo apt-get install postgresql-contrib Restart the database: sudo /etc/init.d/postgresql-8.4 restart Change to the database owner account (e.g., postgres ). Change to the contrib modules' directory: /usr/share/postgresql/8.4/contrib/ Use ls to see a list of the following modules: adminpack

Change Database Collation, Ctype in Postgresql

瘦欲@ 提交于 2019-11-28 11:03:12
how do I change Collation, cType to - en_IN from en_US.UTF-8 List of databases Name | Owner | Encoding | Collation | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres : postgres=CTc/postgres my current postgresversion is 8.4 ive installed it using sudo apt-get install postgresql-8.4 postgresql-contrib-8.4 im doing

Hashing a String to a Numeric Value in PostgreSQL

旧巷老猫 提交于 2019-11-28 05:19:20
I need to Convert Strings stored in my Database to a Numeric value. Result can be Integer (preferred) or Bigint. This conversion is to be done at Database side in a PL/pgSQL function. Can someone please point me to some algorithm or any API's that can be used to achieve this? I have been searching for this on Google for hours now, could not find anything useful so far :( Just keep the first 32 bits or 64 bits of the MD5 hash. Of course, it voids the main property of md5 (=the probability of collision being infinitesimal) but you'll still get a wide dispersion of values which presumably is good

Iterating over integer[] in PL/pgSQL

为君一笑 提交于 2019-11-27 19:37:34
I am trying to loop through an integer array ( integer[] ) in a plpgsql function. Something like this: declare a integer[] = array[1,2,3]; i bigint; begin for i in a loop raise notice "% ",i; end loop; return true; end In my actual use case the integer array a is passed as parameter to the function. I get this error: ERROR: syntax error at or near "$1" LINE 1: $1 How to loop through the array properly? Erwin Brandstetter DECLARE a integer[] := array[1,2,3]; i integer; -- int, not bigint! BEGIN FOR i IN 1 .. array_upper(a, 1) LOOP RAISE NOTICE '%', a[i]; -- single quotes! END LOOP; RETURN TRUE;

Fetch records that are non zero after the decimal point in PostgreSQL

爱⌒轻易说出口 提交于 2019-11-27 15:37:16
I have a table with an amount field of type Numeric . It contains different amount values. For example 5.00 7.13 8.86 6.00 1.00 ... etc. I've to fetch only those records that are nonzero after the decimal point. ie, fetch only the records corresponding to the amounts 7.13 8.86 How can I do it? numeric is exact! Unlike claimed by another answer, numeric is not a floating-point type , but an arbitrary precision type as defined by the SQL standard. Storage is exact . I quote the manual: The type numeric can store numbers with a very large number of digits and perform calculations exactly. It is

How do I import modules or install extensions in Postgres 8.4?

余生长醉 提交于 2019-11-27 09:15:01
问题 I'm trying to import several modules that come bundled with 8.4.1 postgres, and all the commands to do so (such as contrib.import etc) do not work or cannot be found. Please help me. 回答1: To install PostgreSQL contrib modules on Ubuntu or Kubuntu (or similar Linux distributions): Install the contrib package: sudo apt-get install postgresql-contrib Restart the database: sudo /etc/init.d/postgresql-8.4 restart Change to the database owner account (e.g., postgres ). Change to the contrib modules

Select (retrieve) all records from multiple schemas using Postgres

懵懂的女人 提交于 2019-11-27 05:21:45
I have a PostgreSQL database with some schemas, like below: My_Database |-> Schemas |-> AccountA |-> AccountB |-> AccountC |-> AccountD |-> AccountE . . . |-> AccountZ All schemas have a table called product which has a column called title . I would like to know if is possible to execute a select statement to retrieve all records from all schemas with a certain conditional. The only way I found until now is to run a query account by account, like below. SET search_path TO AccountA; SELECT title FROM product WHERE title ILIKE '%test%'; Schemas are created dynamically , so I don't know their

Hashing a String to a Numeric Value in PostgreSQL

ε祈祈猫儿з 提交于 2019-11-27 00:43:28
问题 I need to Convert Strings stored in my Database to a Numeric value. Result can be Integer (preferred) or Bigint. This conversion is to be done at Database side in a PL/pgSQL function. Can someone please point me to some algorithm or any API's that can be used to achieve this? I have been searching for this on Google for hours now, could not find anything useful so far :( 回答1: Just keep the first 32 bits or 64 bits of the MD5 hash. Of course, it voids the main property of md5 (=the probability

Iterating over integer[] in PL/pgSQL

…衆ロ難τιáo~ 提交于 2019-11-26 22:49:29
问题 I am trying to loop through an integer array ( integer[] ) in a plpgsql function. Something like this: declare a integer[] = array[1,2,3]; i bigint; begin for i in a loop raise notice "% ",i; end loop; return true; end In my actual use case the integer array a is passed as parameter to the function. I get this error: ERROR: syntax error at or near "$1" LINE 1: $1 How to loop through the array properly? 回答1: DECLARE a integer[] := array[1,2,3]; i integer; -- int, not bigint! BEGIN FOR i IN 1 .