Could anyone help me to update search path dynamically in PostgreSQL without change in conf files? because I don't want to restart my Postgres service once my application is up.
Use the SET command to issue, for example:
SET search_path TO myschema,public;
Alternatively you can use
ALTER ROLE your_db_user SET search_path TO ....;
so you won't have to execute the SET on each connection.
Related
With SESSION and LOCAL below, I cannot set a parameter persistently in PostgreSQL:
SET SESSION log_statement = 'all'
SET LOCAL log_statement = 'all'
Actually with PERSIST and GLOBAL below in MySQL, I can set a parameter persistently and semi-persistently respectively:
SET PERSIST transaction_isolation = 'READ-UNCOMMITTED';
SET GLOBAL transaction_isolation = 'READ-COMMITTED';
So, are there any ways to set a parameter persistently by a query in PostgreSQL?
You need to use ALTER SYSTEM if you want to change it globally for all databases and users. Or change it in postgresql.conf.
Note that you need to reload the configuration if you do that (depending on the parameter you might even need to restart Postgres completely - this is documented for each property)
If you only want to change it for a specific database, use ALTER DATABASE
If you only want to change it for a user, use ALTER USER
I have a number of command that I want to do from the GUI. I want to do many groups of these, but I can't get a single group to work. I presume I need to somehow force commits between them, but I can't figure out how to do that. If I execute each one of these commands by itself in order, everything works as expected.
I'm using the EPSG.dat from GeoTools' EPSG.zip.
unzip EPSG.zip
perl -pi -e 's/readonly=true/readonly=false/' EPSG.properties
java -jar hsqldb-2.4.1.jar
jdbc:hsqldb:file:./EPSG
SET AUTOCOMMIT true; -- Press Execute SQL, but this doesn't seem to help.
CREATE TEXT TABLE EPSG_UNITOFMEASURE_COPY (LIKE EPSG_UNITOFMEASURE);
GRANT all ON EPSG_UNITOFMEASURE_COPY TO public;
SET TABLE EPSG_UNITOFMEASURE_COPY SOURCE 'EPSG_UNITOFMEASURE_COPY.csv;encoding=UTF-8';
INSERT INTO EPSG_UNITOFMEASURE_COPY SELECT * FROM EPSG_UNITOFMEASURE;
SET TABLE EPSG_UNITOFMEASURE_COPY SOURCE OFF;
I then get an error of:
user lacks privilege or object not found: EPSG_UNITOFMEASURE_COPY / Error Code: -5501 / State: 42501
I am pretty sure this is an object not found case.
You cannot execute these commands as one block. When a schema definition statement refers to a schema object, that object must already exist.
Execute the CREATE TEXT TABLE, then you can execute the rest as a block.
In my website I have some value's field that must change depending on the change in another value's field, so i want them update automatically
for example: update the status of all students that haven't any courses by query:
UPDATE `students`
SET `completed` = IF( `remainCourses` = 0 is true, 1, `completed`);
Maybe someone is wondering why I do not put them in the pages of the site within the php code? Because I need these values on several pages and should be updated, it's difficult to make a query in each page so i wonder if can I put a SQL query on PHPMyadmin to implement automatically? which will make it easier
You can use MySql's Event Scheduler
You first need to configure it
SET GLOBAL event_scheduler = ON;
then
CREATE EVENT myevent
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
UPDATE myschema.mytable SET mycol = mycol + 1;
Reference
you can also use commandline/shell to execute your script
mysql -h "server-name" -u "root" "-pXXXXXXXX" "database-name" < "filename.sql"
if you are on Windows, you can use TaskScheduler to schedule your script
if you are on Linux, you can use crontab to schedule your script
Edit: OP reported that he is using cPanel
You can schedule your jobs using cPanel, Read this
I have a .sql file with name Alter_table.sql which have the following code.
alter table mytable add newcolumn VARCHAR2(1);
I don't want to edit this file and add a spool command. However I need to execute Alter_table.sql by writing spool in another file (execute_sql.sql) which should look like the below. I am not sure of the correct syntax. Can anyone please help here?
SET SERVEROUTPUT ON
SET DEFINE OFF
SPOOL Alter_Table_STD_SOURCE.log
EXEC username/password#database `Alter_table.sql`
SPOOL OFF;
SET DEFINE ON
SET SERVEROUTPUT OFF
(Thanks to Alex Poole) :-)
You need to connect first, then run your .sql file in the wrapper script using the '#' sign or 'START' commands:
...
-- Connect if not already connected.
CONNECT username/password#database
#Alter_table.sql
...
I'm not sure its a good idea to keep login/password in a file but you need to take security into account.
I am new in oracle and doing practice for the PL/SQL. I have one question i.e. :
how to set serveroutput ON permanently in oracle. Is their any way that we use to set it permanently ON?
If you are refering to SQL*Plus you should set this in your glogin.sql file.
You can find this file in ORACLE_HOME\sqlplus\admin.
As far as I know there is no way of setting server output ON permanently.
But if this question is connected to fact that for every new session in SQL developer, 1 needs to execute SET SERVEROUTPUT ON statement in beginning for seeing PL/SQL code result, then solution is Go to view->DBMS_Output
Then below you will see dbms output window. There is a plus(+) button there. Click and add schema on which you are working currently. Then PL/SQL script output can be seen there.