Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在postgresql中重置自动递增计数器_Sql_Postgresql_Auto Increment_Reset - Fatal编程技术网

在postgresql中重置自动递增计数器

在postgresql中重置自动递增计数器,sql,postgresql,auto-increment,reset,Sql,Postgresql,Auto Increment,Reset,我想强制表的自动递增字段为某个值,不幸的是,我的查询似乎失败了 ALTER SEQUENCE categories_categoryid_seq RESTART WITH 1; ERROR: relation "your_sequence_name" does not exist 我的表格categories包含以下列: 类别 功能 名字 编辑:我的创建查询: -- Table: public.categories -- DROP TABLE public.categories; C

我想强制表的自动递增字段为某个值,不幸的是,我的查询似乎失败了

ALTER SEQUENCE categories_categoryid_seq RESTART WITH 1;
ERROR:  relation "your_sequence_name" does not exist
我的表格
categories
包含以下列:

  • 类别
  • 功能
  • 名字
编辑:我的创建查询:

-- Table: public.categories

-- DROP TABLE public.categories;

CREATE TABLE public.categories
(
    categoryid bigint NOT NULL,
    functions character varying(255) COLLATE pg_catalog."default" NOT NULL,
    name character varying(255) COLLATE pg_catalog."default" NOT NULL,
    CONSTRAINT categories_pkey PRIMARY KEY (categoryid)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.categories
    OWNER to postgres;

您可以验证
DEFAULT
子句中定义的名称序列:

SELECT column_name, column_default
FROM information_schema.columns
WHERE table_schema = 'myschema'
   AND table_name = 'categories'
ORDER BY ordinal_position;

然后你就知道该重置哪个序列了

您可以验证
DEFAULT
子句中定义的名称序列:

SELECT column_name, column_default
FROM information_schema.columns
WHERE table_schema = 'myschema'
   AND table_name = 'categories'
ORDER BY ordinal_position;

然后你就知道该重置哪个序列了

上述问题中没有创建序列,因为您没有添加序列或序列:(根据脚本)。bigint必须是bigserial或serial

如果要检查,则创建序列或不运行此脚本

Select column_default 
from information_schema.columns 
where table_name = 'categories' and column_name = 'categoryid';

上述问题中没有创建序列,因为您没有添加序列或序列:(根据脚本)。bigint必须是bigserial或serial

如果要检查,则创建序列或不运行此脚本

Select column_default 
from information_schema.columns 
where table_name = 'categories' and column_name = 'categoryid';

你确定这是序列的名字吗?您是否使用pgAdmin或类似工具进行过检查?如果没有,请尝试前置模式…是的,pgadmin已打开。例如,下面的查询非常有效:SELECT*FROM public.CATEGORES ORDER BY categoryid显然没有使用该名称的序列。请回答您的问题,并向我们展示完整的
create table
语句(用于
categories
)和序列的
create
语句。该列的定义没有默认值,也不是
serial
。你为什么期望序列首先存在?(另外:将varchar限制为255个字符根本没有性能或存储优势。255并不是实现更快处理的神奇限制)您确定这是序列的名称吗?您是否使用pgAdmin或类似工具进行过检查?如果没有,请尝试前置模式…是的,pgadmin已打开。例如,下面的查询非常有效:SELECT*FROM public.CATEGORES ORDER BY categoryid显然没有使用该名称的序列。请回答您的问题,并向我们展示完整的
create table
语句(用于
categories
)和序列的
create
语句。该列的定义没有默认值,也不是
serial
。你为什么期望序列首先存在?(另外:将varchar限制为255个字符根本没有性能或存储优势。255并不是实现更快处理的神奇限制)使用以下查询:从INFORMATION_SCHEMA.COLUMNS,其中table_name='categories'和column_name,如'categoryid',我得到了结果:categoryid,但仍然。。。顺序不正确correct@user3657270重要信息位于
列\u default
列中。你得到了什么?通过以下查询:从INFORMATION_SCHEMA.COLUMNS,其中table_name='categories'和column_name,比如'categoryid',我得到了我的结果:categoryid,但仍然。。。顺序不正确correct@user3657270重要信息位于
列\u default
列中。你得到了什么?