Rails 使用 PostgreSQL 加载模式后出现语法错误
Rails syntax error after schema load with PostgreSQL
我有一个问题,我无法理解,也无法在其他地方找到解决方案。问题是,当我尝试使用
加载架构时
load "#{Rails.root}/db/sctructure.sql"
出现错误。
postgresql版本是9.5.1,pggem是0.8.1。
据我所知,pg gem 无法识别转储文件的注释。
你曾经 运行 做过类似的事情吗?
SyntaxError: /Users/user/Documents/workspace/app/db/structure.sql:2: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
-- PostgreSQL database dump
^
/Users/user/Documents/workspace/app/db/structure.sql:5: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
-- Dumped from database version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:5: unexpected fraction part after numeric literal
-- Dumped from database version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:6: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
-- Dumped by pg_dump version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:6: unexpected fraction part after numeric literal
-- Dumped by pg_dump version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:17: syntax error, unexpected tLABEL
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
^
/Users/user/Documents/workspace/app/db/structure.sql:17: syntax error, unexpected ':', expecting end-of-input
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
structure.sql 文件的一部分:
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.1
-- Dumped by pg_dump version 9.5.1
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: accounts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE accounts (
id integer NOT NULL,
name character varying,
logo character varying,
website character varying,
subdomain character varying,
active boolean,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: accounts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE accounts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: accounts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE accounts_id_seq OWNED BY accounts.id;
--
-- Name: addresses; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE addresses (
id integer NOT NULL,
location_id integer,
location_type character varying,
street character varying,
number character varying,
zip character varying,
city character varying,
country character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: addresses_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE addresses_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: addresses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE addresses_id_seq OWNED BY addresses.id;
--
-- Name: administrators; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE administrators (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: administrators_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE administrators_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: administrators_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE administrators_id_seq OWNED BY administrators.id;
--
-- Name: agreements; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE agreements (
id integer NOT NULL,
employee_id integer,
client_id integer,
contract_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: agreements_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE agreements_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: agreements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE agreements_id_seq OWNED BY agreements.id;
--
-- Name: api_authorizations; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE api_authorizations (
id integer NOT NULL,
authorizable_id integer,
authorizable_type character varying,
client_id character varying,
client_secret character varying,
access_token character varying,
access_expires_at timestamp without time zone,
download_token character varying,
token_type character varying,
scope character varying,
refresh_token character varying,
refresh_expires_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: api_authorizations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE api_authorizations_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: api_authorizations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE api_authorizations_id_seq OWNED BY api_authorizations.id;
--
-- Name: billings; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE billings (
id integer NOT NULL,
user_id integer,
bank_account_number character varying,
bic character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: billings_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE billings_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: billings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE billings_id_seq OWNED BY billings.id;
--
-- Name: clients; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE clients (
id integer NOT NULL,
external_id character varying,
url_digest character varying,
employee_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: clients_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE clients_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: clients_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE clients_id_seq OWNED BY clients.id;
--
-- Name: companies; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE companies (
id integer NOT NULL,
name character varying,
revenue numeric(15,2),
employee_number integer,
sector character varying,
foundation_date date,
tax_number character varying,
vat_id character varying,
total_salaries numeric(15,2),
client_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: companies_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE companies_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: companies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE companies_id_seq OWNED BY companies.id;
--
-- Name: contacts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE contacts (
id integer NOT NULL,
honorific integer,
title character varying,
first_name character varying,
last_name character varying,
birth_date date,
telephone character varying,
user_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: contacts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE contacts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contacts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE contacts_id_seq OWNED BY contacts.id;
--
-- Name: contract_categories; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE contract_categories (
id integer NOT NULL,
name character varying,
contract_group_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: contract_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE contract_categories_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contract_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE contract_categories_id_seq OWNED BY contract_categories.id;
--
-- Name: contract_groups; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE contract_groups (
id integer NOT NULL,
name character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: contract_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE contract_groups_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contract_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
您看到此错误是因为您无法 load
sql 文件。 load
仅用于加载 ruby 个文件。
我有一个问题,我无法理解,也无法在其他地方找到解决方案。问题是,当我尝试使用
加载架构时load "#{Rails.root}/db/sctructure.sql"
出现错误。 postgresql版本是9.5.1,pggem是0.8.1。 据我所知,pg gem 无法识别转储文件的注释。 你曾经 运行 做过类似的事情吗?
SyntaxError: /Users/user/Documents/workspace/app/db/structure.sql:2: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
-- PostgreSQL database dump
^
/Users/user/Documents/workspace/app/db/structure.sql:5: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
-- Dumped from database version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:5: unexpected fraction part after numeric literal
-- Dumped from database version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:6: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
-- Dumped by pg_dump version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:6: unexpected fraction part after numeric literal
-- Dumped by pg_dump version 9.5.1
^
/Users/user/Documents/workspace/app/db/structure.sql:17: syntax error, unexpected tLABEL
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
^
/Users/user/Documents/workspace/app/db/structure.sql:17: syntax error, unexpected ':', expecting end-of-input
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
structure.sql 文件的一部分:
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.1
-- Dumped by pg_dump version 9.5.1
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: accounts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE accounts (
id integer NOT NULL,
name character varying,
logo character varying,
website character varying,
subdomain character varying,
active boolean,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: accounts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE accounts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: accounts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE accounts_id_seq OWNED BY accounts.id;
--
-- Name: addresses; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE addresses (
id integer NOT NULL,
location_id integer,
location_type character varying,
street character varying,
number character varying,
zip character varying,
city character varying,
country character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: addresses_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE addresses_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: addresses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE addresses_id_seq OWNED BY addresses.id;
--
-- Name: administrators; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE administrators (
id integer NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: administrators_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE administrators_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: administrators_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE administrators_id_seq OWNED BY administrators.id;
--
-- Name: agreements; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE agreements (
id integer NOT NULL,
employee_id integer,
client_id integer,
contract_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: agreements_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE agreements_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: agreements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE agreements_id_seq OWNED BY agreements.id;
--
-- Name: api_authorizations; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE api_authorizations (
id integer NOT NULL,
authorizable_id integer,
authorizable_type character varying,
client_id character varying,
client_secret character varying,
access_token character varying,
access_expires_at timestamp without time zone,
download_token character varying,
token_type character varying,
scope character varying,
refresh_token character varying,
refresh_expires_at timestamp without time zone,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: api_authorizations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE api_authorizations_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: api_authorizations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE api_authorizations_id_seq OWNED BY api_authorizations.id;
--
-- Name: billings; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE billings (
id integer NOT NULL,
user_id integer,
bank_account_number character varying,
bic character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: billings_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE billings_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: billings_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE billings_id_seq OWNED BY billings.id;
--
-- Name: clients; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE clients (
id integer NOT NULL,
external_id character varying,
url_digest character varying,
employee_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: clients_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE clients_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: clients_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE clients_id_seq OWNED BY clients.id;
--
-- Name: companies; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE companies (
id integer NOT NULL,
name character varying,
revenue numeric(15,2),
employee_number integer,
sector character varying,
foundation_date date,
tax_number character varying,
vat_id character varying,
total_salaries numeric(15,2),
client_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: companies_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE companies_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: companies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE companies_id_seq OWNED BY companies.id;
--
-- Name: contacts; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE contacts (
id integer NOT NULL,
honorific integer,
title character varying,
first_name character varying,
last_name character varying,
birth_date date,
telephone character varying,
user_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: contacts_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE contacts_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contacts_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE contacts_id_seq OWNED BY contacts.id;
--
-- Name: contract_categories; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE contract_categories (
id integer NOT NULL,
name character varying,
contract_group_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: contract_categories_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE contract_categories_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contract_categories_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE contract_categories_id_seq OWNED BY contract_categories.id;
--
-- Name: contract_groups; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE contract_groups (
id integer NOT NULL,
name character varying,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: contract_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE contract_groups_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: contract_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
您看到此错误是因为您无法 load
sql 文件。 load
仅用于加载 ruby 个文件。