Tag Archives: Postgres

[Solved] ERROR #42601 syntax error at or near “)“

 

Background

orm:go-pg

Execute whereIn error: Error #42601} syntax} error at} or “near”)

As shown in the figure

The query is as follows:

err = db.Model(&model.Abc{}).WhereIn(“id in (?)”, ids).Column(“id”).Column(“name”).Select(&records)

If IDS is an empty slice, this error will be reported at this time

Solution:

The slices passed in should not be empty. From the business point of view, the length of the list of condition ids to be checked is 0 then the results must not be checked, so you can make a judgment in the outer layer, ids length is 0 then do not take the sql query can be.

Solution to the error of ODBC driver in windows installation of Postgres database

Solution to the error of ODBC driver in windows installation of Postgres database

Installing postgressql driver on Windows reports an error “the specified module cannot be found”

terms of settlement

Find another system of the same version, which can install the modified drive computer normally. Paste the contents of the two folders in the windows folder of drive C into the system that cannot be installed

copy the two folders in the above figure to the problem computer. Select duplicate files, ignore them, and do not select replacement, so as not to affect the use of the system

[Solved] Postgres Start Error: Job for postgresql.service failed because the control process exited with error code.

error message

Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.

Execute systemctl status postgresql.service as prompted

Open this file

vim /usr/lib/systemd/system/postgresql.service
Found not modified to their own initialization of the specified path, modify can

Postgres uuid_generate_v1() does not exist [How to Solve]

 

1、 Phenomenon:

schema=# select uuid_generate_v1();

ERROR: function uuid_generate_v1() does not exist

Line 1: select uuid_generate_v1();

^

Warning: No function matches the given name and argument types. You might need to add explicit type casts.

Time: 14.543 ms

2、 Reason:

By default, Postgres has no UUID_ generate_ V1 method, you need to install the extension and enable UUID ossp to use this method.

3、 Solution:

1. Install UUID ossp extension dependent environment

You can use compile install or Yum install, because my environment here is postgres10, yum install, so the yum install extension is preferred.

yum install -y postgresql10-contrib

2. Enable UUID ossp extension

postgres=# create extension "uuid-ossp" ;

CREATE EXTENSION

3. Verification

postgres-# \dx

Installed extensions list

Name | Version | Architecture Mode | Description

-----------+------+------------+-------------------------------------------------

plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language

uuid-ossp | 1.1 | public | generate universally unique identifiers (UUIDs)

More details

postgres=# \dx+
        Object used to extend "plpgsql"
               Object description                
---------------------------------------
 Function plpgsql_call_handler()
 function plpgsql_inline_handler(internal)
 function plpgsql_validator(oid)
 Language plpgsql
(4 rows of records)

     object for extending "uuid-ossp"
             Object description             
----------------------------------
 Function uuid_generate_v1()
 function uuid_generate_v1mc()
 function uuid_generate_v3(uuid,text)
 function uuid_generate_v4()
 function uuid_generate_v5(uuid,text)
 function uuid_nil()
 function uuid_ns_dns()
 function uuid_ns_oid()
 function uuid_ns_url()
 function uuid_ns_x500()
(10 lines of records)

Execute again

postgres=# select uuid_generate_v1();
           uuid_generate_v1           
--------------------------------------
 9ffd8cc8-db44-11eb-8952-0050568a41b8
(1 line record)

Pg_dump Error: pg_dump: No matching tables were found,pg_dump: schema with OID 1515227 does not exi

Use SQL query
to create functions and copy them directly

CREATE OR REPLACE FUNCTION public.show_create_table(
  in_schema_name varchar,
  in_table_name varchar
)
RETURNS text
LANGUAGE plpgsql VOLATILE
AS
$$
  DECLARE
    -- the ddl we're building
    v_table_ddl text;

    -- data about the target table
    v_table_oid int;

    -- records for looping
    v_column_record record;
    v_constraint_record record;
    v_index_record record;
  BEGIN
    -- grab the oid of the table; https://www.postgresql.org/docs/8.3/catalog-pg-class.html
    SELECT c.oid INTO v_table_oid
    FROM pg_catalog.pg_class c
    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
    WHERE 1=1
      AND c.relkind = 'r' -- r = ordinary table; https://www.postgresql.org/docs/9.3/catalog-pg-class.html
      AND c.relname = in_table_name -- the table name
      AND n.nspname = in_schema_name; -- the schema

    -- throw an error if table was not found
    IF (v_table_oid IS NULL) THEN
      RAISE EXCEPTION 'table does not exist';
    END IF;

    -- start the create definition
    v_table_ddl := 'CREATE TABLE ' || in_schema_name || '.' || in_table_name || ' (' || E'\n';

    -- define all of the columns in the table; https://stackoverflow.com/a/8153081/3068233
    FOR v_column_record IN
      SELECT
        c.column_name,
        c.data_type,
        c.character_maximum_length,
        c.is_nullable,
        c.column_default
      FROM information_schema.columns c
      WHERE (table_schema, table_name) = (in_schema_name, in_table_name)
      ORDER BY ordinal_position
    LOOP
      v_table_ddl := v_table_ddl || '  ' -- note: two char spacer to start, to indent the column
        || v_column_record.column_name || ' '
        || v_column_record.data_type || CASE WHEN v_column_record.character_maximum_length IS NOT NULL THEN ('(' || v_column_record.character_maximum_length || ')') ELSE '' END || ' '
        || CASE WHEN v_column_record.is_nullable = 'NO' THEN 'NOT NULL' ELSE 'NULL' END
        || CASE WHEN v_column_record.column_default IS NOT null THEN (' DEFAULT ' || v_column_record.column_default) ELSE '' END
        || ',' || E'\n';
    END LOOP;

    -- define all the constraints in the; https://www.postgresql.org/docs/9.1/catalog-pg-constraint.html && https://dba.stackexchange.com/a/214877/75296
    FOR v_constraint_record IN
      SELECT
        con.conname as constraint_name,
        con.contype as constraint_type,
        CASE
          WHEN con.contype = 'p' THEN 1 -- primary key constraint
          WHEN con.contype = 'u' THEN 2 -- unique constraint
          WHEN con.contype = 'f' THEN 3 -- foreign key constraint
          WHEN con.contype = 'c' THEN 4
          ELSE 5
        END as type_rank,
        pg_get_constraintdef(con.oid) as constraint_definition
      FROM pg_catalog.pg_constraint con
      JOIN pg_catalog.pg_class rel ON rel.oid = con.conrelid
      JOIN pg_catalog.pg_namespace nsp ON nsp.oid = connamespace
      WHERE nsp.nspname = in_schema_name
      AND rel.relname = in_table_name
      ORDER BY type_rank
    LOOP
      v_table_ddl := v_table_ddl || '  ' -- note: two char spacer to start, to indent the column
        || 'CONSTRAINT' || ' '
        || v_constraint_record.constraint_name || ' '
        || v_constraint_record.constraint_definition
        || ',' || E'\n';
    END LOOP;

    -- drop the last comma before ending the create statement
    v_table_ddl = substr(v_table_ddl, 0, length(v_table_ddl) - 1) || E'\n';

    -- end the create definition
    v_table_ddl := v_table_ddl || ');' || E'\n';

    -- suffix create statement with all of the indexes on the table
    FOR v_index_record IN
      SELECT indexdef
      FROM pg_indexes
      WHERE (schemaname, tablename) = (in_schema_name, in_table_name)
    LOOP
      v_table_ddl := v_table_ddl
        || v_index_record.indexdef
        || ';' || E'\n';
    END LOOP;

    -- return the ddl
    RETURN v_table_ddl;
  END;
$$;

example

example:
SELECT * FROM public.show_create_table('public', 'example_table');

produce

CREATE TABLE public.example_table (
  id bigint NOT NULL DEFAULT nextval('test_tb_for_show_create_on_id_seq'::regclass),
  name character varying(150) NULL,
  level character varying(50) NULL,
  description text NOT NULL DEFAULT 'hello there!'::text,
  CONSTRAINT test_tb_for_show_create_on_pkey PRIMARY KEY (id),
  CONSTRAINT test_tb_for_show_create_on_level_check CHECK (((level)::text = ANY ((ARRAY['info'::character varying, 'warn'::character varying, 'error'::character varying])::text[])))
);
CREATE UNIQUE INDEX test_tb_for_show_create_on_pkey ON public.test_tb_for_show_create_on USING btree (id);

Stack overflow moved here. I’ve been looking for it for a long time. It’s easy to use

Postgres Multiple data insertion error: The ‘default‘ dialect with current database version settings does not support

Error report of inserting multiple data into postges database by Python

Solutions for error reporting related information

Information related to error reporting

Error report content: the 'default' dialect with current database version settings does not support
Python version: 3.7
psotgres version: 13
specific situation: single data insertion is normal, multiple data insertion may report errors once, but not every time.

Solution

At first, I thought there was a problem with the database version, but I still couldn’t change Postgres 10