How can I find what languages have been loaded into EnterpriseDB(PL/pgsql, SPL, Java)? EnterpriseDB is built on top of PostgreSQL if anyone knows of a way to find the loaded languages on PostgreSQL. It should work the same.
The installed languages are registered in pl_language, e.g.:
steve#steve#[local] =# select * from pg_language;
lanname | lanowner | lanispl | lanpltrusted | lanplcallfoid | lanvalidator | lanacl
----------+----------+---------+--------------+---------------+--------------+--------
internal | 10 | f | f | 0 | 2246 |
c | 10 | f | f | 0 | 2247 |
sql | 10 | f | t | 0 | 2248 |
plpgsql | 10 | t | t | 73259 | 73260 |
(4 rows)
Check the "pg_language" system catalogue (hopefully EDB is not that different from Postgres).
Related
I am using Postgresql 9.4.
I have this table recorded:
Colonne | Type | Modificateurs
---------+-----------------------+---------------
noemp | integer | non NULL
nomemp | character varying(15) |
emploi | character varying(14) |
mgr | integer |
dateemb | date |
sal | real |
comm | real |
nodept | integer |
Which has those values inside:
noemp | nomemp | emploi | mgr | dateemb | sal | comm | nodept
-------+-----------+----------------+------+------------+------+------+--------
7369 | SERGE | FONCTIONNAIRE | 7902 | 1980-12-07 | 800 | | 20
7499 | BRAHIM | VENDEUR | 7698 | 1981-02-20 | 1600 | 300 | 30
7521 | NASSIMA | VENDEUR | 7698 | 1981-02-22 | 1250 | 500 | 30
7566 | LUCIE | GESTIONNAIRE | 7839 | 1981-04-02 | 2975 | | 20
7654 | MARTIN | VENDEUR | 7698 | 1981-09-28 | 1250 | 1400 | 30
7698 | BENJAMIN | GESTIONNAIRE | 7839 | 1981-05-01 | 2850 | | 30
7782 | DAYANE | GESTIONNAIRE | 7839 | 1981-06-09 | 2450 | | 10
7788 | ARIJ | ANALYSTE | 7566 | 1982-12-09 | 3000 | | 20
7839 | MAYAR | PRESIDENT | | 1981-11-17 | 5000 | | 10
7844 | ROI | VENDEUR | 7698 | 1981-09-08 | 1500 | 0 | 30
7876 | VIRGINIE | FONCTIONNAIRE | 7788 | 0983-01-12 | 1100 | | 20
7902 | ASMA | ANALYSTE | 7566 | 1981-12-03 | 3000 | | 20
7934 | SIMONE | FONCTIONNAIRE | 7782 | 1982-01-23 | 1300 | | 10
7900 | LYNA | FONCTIONNAIRE | 7698 | 1981-12-03 | 950 | | 30
(14 lignes)
When I make a function to count the number of "nodept" with an asked value like this one:
CREATE OR REPLACE FUNCTION depcount(integer)RETURNS integer AS $$
DECLARE
somme integer;
BEGIN
SELECT DISTINCT(COUNT(*)) FROM EMP WHERE nodept=$1 INTO somme ;
RETURN somme;
END$$
LANGUAGE plpgsql;
with a SELECT depcount(30) FROM EMP;
I get this answer:
----------
6
6
6
6
6
6
6
6
6
6
6
6
6
6
(14 lignes)
14 results, as I should normally have only one.
I have to specify that I'm doing this for a course and I can't change the postgresql version, which must be 9.4.
If you have any idea why I get 14 results instead of one ?
thank you.
You're executing the function once per row, running the SELECT COUNT(*) 14 times and getting the result once for each row.
You probably want SELECT depcount(30) (without aFROM clause), to run the function only once.
On a side note, using a function for this sort of query is a bit overkill in most case in my opinion. You also don't need to use plpgsql, language sql would be enough here (though your function may be a bit more complicated than in your example). Using DISTINCT(COUNT(*)) doesn't really make sense either.
I am struggling to do a loop on a Postgres, but functions on postgres are not my piece of cake.
I have the following table on postgres:
| portfolio_1 | total_risk |
|----------------|------------|
| Top 10 Bets | |
| AAPL34 | 2,06699 |
| DISB34 | 1,712684 |
| PETR4 | 0,753324 |
| PETR3 | 0,087767 |
| VALE3 | 0,086346 |
| LREN3 | 0,055108 |
| AMZO34 | 0,0 |
| Bottom 10 Bets | |
| AAPL34 | 0,0 |
What I'm trying to do is get the values after the "Top 10 Bets" and before the "Botton 10 Bets".
My goal is the following result:
| portfolio_1 | total_risk |
|-------------|------------|
| AAPL34 | 2,06699 |
| DISB34 | 1,712684 |
| PETR4 | 0,753324 |
| PETR3 | 0,087767 |
| VALE3 | 0,086346 |
| LREN3 | 0,055108 |
| AMZO34 | 0,0 |
So, my goal is to take off the "Top 10 Bets", the "Botton 10 Bets" and the AAPL34 after the "Botton 10 Bets", which was repeated.
The quantity of rows is variable (I'm importing it from an Excel file), so I need a loop to do this, right?
SQL tables and result sets represent unordered sets. There is no "before" or "after" unless rows explicitly provide that information.
Let me assume that you have such a column, which I will call id for convenience.
Then you can do this in several ways. Here is one:
select t.*
from t
where t.id > (select min(t2.id) from t t2 where t2.portfolio_1 = 'Top 10 Bets') and
t.id < (select max(t2.id) from t t2 where t2.portfolio_1 = 'Bottom 10 Bets');
In this answer to the question Right query to get the current number of connections in a PostgreSQL DB the poster implies that
SELECT sum(numbackends) FROM pg_stat_database;
and
SELECT count(*) FROM pg_stat_activity;
give the same results.
However, if I do this on my db the first one says 119 and the second one 30.
This is the difference as shown by summing numbackends and counting:
+------+-------------+-------+
| | numbackends | count |
+------+-------------+-------+
| db1 | 1 | 1 |
| db2 | 1 | 1 |
| db3 | 1 | 1 |
| db4 | 1 | 1 |
| db5 | 2 | 2 |
| db6 | 2 | 2 |
| db7 | 12 | 3 | <--
| db8 | 4 | 4 |
| db9 | 5 | 5 |
| db10 | 78 | 35 | <--
+------+-------------+-------+
Why does this difference exist?
How can I list each of the 119-30=89 backends not shown in pg_stat_activity?
I have two database with the same name after a manipulation error (I think).
When I try to dump the one owned by bussiere it always dumps the empty one owned by postgres.
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
dbbiotech | bussiere | SQL_ASCII | C | C |
ddbiotech | postgres | SQL_ASCII | C | C | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | bussiere=CTc/postgres
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
You don't. The name is different: dbbiotech is not ddbiotech.
Looks like a misunderstanding. It wouldn't be possible to have the same name twice in the same DB cluster to begin with. Postgres does not allow it.
I tried to create a language pltcl in postgresql. But, I got this error.
postgres=# CREATE LANGUAGE 'pltcl';
ERROR: could not access file "$libdir/pltcl": No such file or directory
postgres=# select * from pg_pltemplate;
tmplname | tmpltrusted | tmpldbacreate | tmplhandler | tmplvalidator | tmpllibrary | tmplacl
-----------+-------------+---------------+-----------------------+-------------------+------------------+---------
plpgsql | t | t | plpgsql_call_handler | plpgsql_validator | $libdir/plpgsql |
pltcl | t | t | pltcl_call_handler | | $libdir/pltcl |
pltclu | f | f | pltclu_call_handler | | $libdir/pltcl |
plperl | t | t | plperl_call_handler | plperl_validator | $libdir/plperl |
plperlu | f | f | plperl_call_handler | plperl_validator | $libdir/plperl |
plpythonu | f | f | plpython_call_handler | | $libdir/plpython |
After referred the internet, I got the answer. That is,
In order to get pltcl.so you will need to compile the postgres code using --with-tcl configure switch. pltcl does not compile by default with postgres.
How to fix this problem?
You need to install the postgresql-pltcl-9.1 package, replacing the 9.1 with the postgres version you're using if it's different.
sudo apt-get install postgresql-pltcl-9.6 postgresql-plperl-9.6