postgresql-9.2

PostgreSQL - set a default cell value according to another cell value

时光毁灭记忆、已成空白 提交于 2019-11-30 14:31:18
问题 If i have a column say column a of any given values, and i want another column column b to have a default value according to the value of column a In another words: if column a = 'peter' then column b default value = 'doctor' . 回答1: This is not possible with a simple DEFAULT value, as the manual clearly states: The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). You could use a trigger instead: CREATE OR REPLACE

How to Auto Increment Alpha-Numeric value in postgresql?

萝らか妹 提交于 2019-11-30 13:58:17
I am using "PostgreSQL 9.3.5" I have a Table ( StackOverflowTable ) with columns (SoId,SoName,SoDob) . I want a Sequence generator for column SoId which is a Alpha-numeric value. I want to auto increment a Alpha-Numeric Value in postgresql. For eg : SO10001, SO10002, SO10003.....SO99999. Edit: If tomorrow i need to generate a Sequence which can be as SO1000E100, SO1000E101,... and which has a good performance. Then what is the best solution! Use sequences and default value for id: postgres=# CREATE SEQUENCE xxx; CREATE SEQUENCE postgres=# SELECT setval('xxx', 10000); setval -------- 10000 (1

Size limit of JSON data type in PostgreSQL

末鹿安然 提交于 2019-11-30 12:37:11
问题 Does anyone know what is the limit on the size of JSON data type in PostgreSQL 9.2? 回答1: Looking at the source for PostgreSQL 9.2.1: Source: postgresql-9.2.1\src\backend\utils\adt\json.c: /* * Input. */ Datum json_in(PG_FUNCTION_ARGS) { char *text = PG_GETARG_CSTRING(0); json_validate_cstring(text); /* Internal representation is the same as text, for now */ PG_RETURN_TEXT_P(cstring_to_text(text)); } Update for PostgreSQL 9.3.5: The code has changed in the json_in function, but the json

PostgreSQL - set a default cell value according to another cell value

[亡魂溺海] 提交于 2019-11-30 10:52:59
If i have a column say column a of any given values, and i want another column column b to have a default value according to the value of column a In another words: if column a = 'peter' then column b default value = 'doctor' . This is not possible with a simple DEFAULT value, as the manual clearly states : The value is any variable-free expression (subqueries and cross-references to other columns in the current table are not allowed). You could use a trigger instead: CREATE OR REPLACE FUNCTION trg_foo_b_default() RETURNS trigger AS $func$ BEGIN -- For just a few constant options, CASE does

How to insert data into table using stored procedures in postgresql

一曲冷凌霜 提交于 2019-11-30 08:12:19
CREATE TABLE app_for_leave ( sno integer NOT NULL, eid integer, ename varchar(20), sd date, ed date, sid integer, status boolean DEFAULT false, CONSTRAINT pk_snoa PRIMARY KEY (sno) ); Basic Insertion is :: INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status) VALUES(1,101,'2013-04-04','2013-04-04',2,'f' ); ... INSERT INTO app_for_leave(sno, eid, sd, ed, sid, status) VALUES (?, ?, ?, ?, ?, ?); My Requirement:: How to insert data into a table using stored procedures ? PostgreSQL didn't support stored procedures until PG11. Prior to that, you could get the same result using a function. For

Check statistics targets in PostgreSQL

时光怂恿深爱的人放手 提交于 2019-11-30 07:56:05
问题 I have searched but been unable to find any simple, straight forward answer to this. How do I check the current statistics targets used by ANALYZE? 回答1: The setting for the statistics target is stored per column in the catalog table pg_attribute. You can set it like this: ALTER TABLE myschama.mytable ALTER mycolumn SET STATISTICS 127; And check it like this: SELECT attstattarget FROM pg_attribute WHERE attrelid = 'myschama.mytable'::regclass AND attname = 'mycolumn'; Or you just look at the

Socket File “/var/pgsql_socket/.s.PGSQL.5432” Missing In Mountain Lion (OS X Server)

穿精又带淫゛_ 提交于 2019-11-30 06:08:33
问题 I just upgraded my MacMini Server from Lion Server to Mountain Lion using OS X Server. I am having the same problem with PostgreSQL that I did last year when I first installed Lion Server. When I try to do any kind of PostgreSQL terminal command I get the following notorious error message that many have gotten over the years: psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL

What's the easiest way to represent a bytea as a single integer in PostgreSQL?

别说谁变了你拦得住时间么 提交于 2019-11-30 04:55:24
问题 I have a bytea column that contains 14 bytes of data. The last 3 bytes of the 14 contain the CRC code of the data. I would like to extract the CRC as a single integer to be stored in a new column. How would I go about doing this? To clarify, here's one way of doing it in Java: int crc = ((rawData[len - 3] & 0xff) << 16 | (rawData[len - 2] & 0xff) << 8 | (rawData[len - 1] & 0xff)) & 0xffffff; I'm hoping to find a solution without bit shifting, i.e. something like a method that accepts 4 bytes

Get all procedural , user defined functions

情到浓时终转凉″ 提交于 2019-11-30 04:14:07
How to get list of all user defined functions via SQL query ? I find this code here SELECT p.proname, p.pronargs, t.typname FROM pg_proc p, pg_language l, pg_type t WHERE p.prolang = l.oid and p.prorettype = t.oid and l.lanname = 'c' ORDER BY proname; but this gets C-functions How to get user defined, procedural language functions, writen for example in plpgsql language? Craig Ringer Consider: select pp.proname, pl.lanname, pn.nspname, pg_get_functiondef(pp.oid) from pg_proc pp inner join pg_namespace pn on (pp.pronamespace = pn.oid) inner join pg_language pl on (pp.prolang = pl.oid) where pl

Passing a ResultSet into a Postgresql Function

烂漫一生 提交于 2019-11-30 03:52:51
问题 Is it possible to pass the results of a postgres query as an input into another function? As a very contrived example, say I have one query like SELECT id, name FROM users LIMIT 50 and I want to create a function my_function that takes the resultset of the first query and returns the minimum id. Is this possible in pl/pgsql? SELECT my_function(SELECT id, name FROM Users LIMIT 50); --returns 50 回答1: It is not possible to pass an array of generic type RECORD to a plpgsql function which is