PostgreSQL execute statement on same user - but with different privilidges - postgresql

I need to run multiple user-defined SQL scripts - some using schema modification privileges, others only data modification privileges.
I can do this by executing them using different users (with adequate privileges), however I need to execute all scripts in single transaction.
Is there a way to specify privileges for single SQL statement on existing connection?
Thank you!

Related

Run SQL script on multiple schemas with Flyway

I am migrating the DB using Flyway. I have a SQL script file which need to run on multiple schemas hosted on a single database.
In my SQL file if I mention ${db_schema} as the parameter and supply with different schema names, will that work? Is there any other approaches to handle this scenario?
SET search_path TO ${db_schema};
You should be able to use placeholders in flyway to handle more than one schema. Here's an article that outlines how that works.

Scheduling a job with Postgresql for non-admin user

Is there a tool that will allow me to schedule Postgresql queries to run at regular intervals without being an Admin? I'm looking for solutions that would work on a Mac.
I only have write privileges (insert, update, delete) on certain schemas of the database but would like to schedule a query that runs on one of these schemas every day.
pgAgent is the obvious choice but I think I need to be an admin to use/install that.
Is there a tool that will allow me to schedule Postgresql queries to run at regular intervals without being an Admin? I'm looking for solutions that would work on a Mac.
Use pg_cron
INSERT INTO cron.job (schedule, command, nodename, nodeport, database, username)
VALUES ('0 4 * * *', 'VACUUM', 'worker-node-1', 5432, 'postgres', 'marco');
this requires you to install the extension as an admin.
You can also run crontab -e assuming it's supported by OSX. If you want to, as a regular user, set up a task to run (even non-DB tasks).

Is it possible to edit firebird database, alter trigger without connecting to it?

Is it possible to edit firebird database, alter trigger without connecting to it, using raw .fdb file or .gbak?
Although with sufficient knowledge of the internal structure of Firebird it would be possible to edit the file directly, in practice that is not a viable way (and would be a great way to corrupt your database).
Users with admin rights can disable firing database triggers on connect for a connection, see also Database Triggers.
For example when you use ISQL, you can start it with isql -nodbtriggers. This only works with SYSDBA, or if you have the RDB$ADMIN role and if you specify that role on connect.

Setting up environment for SQL queries

I know the basic syntax of queries but otherwise I'm a beginner with SQL.
I have an SQL file (.sql) and I downloaded a couple programs (pgadmin and sql workbench).
I have no idea how to get from where I am now to actually writing queries and finding information. How do I set up so I can actually import my SQL file and start writing queries?
pgAdmin is the default GUI for PostgreSQL.
SQL Workbench is a free, DBMS-independent, cross-platform SQL query tool.
Either way, you need to connect to a database to actually run queries. The DBMS can either run on your local machine or you can connect to a remote server - where you need access privileges of course.

What is the standard way to write scripts to manipulate a Postgres database?

It seems that psql has no branching, and doesn't support PL/pgSQL blocks either. How do people automate Postgres database actions? Should I write functions, and just call the functions from psql?
PostgreSQL 9.0 and up lets you execute an anonymous code block using a DO statement.
If you need to support earlier versions of Postgres, you could, within a transaction, create a stored procedure, execute it, and delete it.
psql is just a client that you can use to interact with postgresql server. pl/pgsql is executed in the server and can be added/altered using psql (or any other client).
Maybe you find more on what you're looking for here: http://www.postgresql.org/docs/9.0/static/plpgsql.html