now() default values are all showing same timestamp

That is expected and documented behaviour: From the manual: Since these functions return the start time of the current transaction, their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the “current” time, so that multiple modifications within … Read more

PostgreSQL – dynamic value as table name [duplicate]

You will need to use the PL/PgSQL EXECUTE statement, via a DO block or PL/PgSQL function (CREATE OR REPLACE FUNCTION … LANGUAGE plpgsql). Dynamic SQL is not supported in the ordinary SQL dialect used by PostgreSQL, only in the procedural PL/PgSQL variant. DO $$ BEGIN EXECUTE format(‘CREATE TABLE %I AS SELECT * FROM backup’, ‘backup_’ … Read more

How to take backup of functions only in Postgres

use pg_getfunctiondef; see system information functions. pg_getfunctiondef was added in PostgreSQL 8.4. SELECT pg_get_functiondef(‘proc_name’::regproc); To dump all functions in a schema you can query the system tables in pg_catalog; say if you wanted everything from public: SELECT pg_get_functiondef(f.oid) FROM pg_catalog.pg_proc f INNER JOIN pg_catalog.pg_namespace n ON (f.pronamespace = n.oid) WHERE n.nspname=”public”; it’s trivial to change … Read more

SELECT .. INTO to create a table in PL/pgSQL

Try CREATE TEMP TABLE mytable AS SELECT * FROM orig_table; Per http://www.postgresql.org/docs/current/static/sql-selectinto.html CREATE TABLE AS is functionally similar to SELECT INTO. CREATE TABLE AS is the recommended syntax, since this form of SELECT INTO is not available in ECPG or PL/pgSQL, because they interpret the INTO clause differently. Furthermore, CREATE TABLE AS offers a superset … Read more

Is there data visualisation tool for postgresql which is capable of displaying inter schema relations as well? [closed]

I’ve recently discovered DBeaver. It automatically detects relations between tables in a visual manner. You can move tables around, change colors, see foreign keys, etc. It’s extremely good. Fully compatible with PostgreSQL Querying and manipulating data using the GUI is extremely easy. Not only that you can use it with all major SQL and noSQL … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)